Code Monkey home page Code Monkey logo

Comments (5)

yihui avatar yihui commented on June 18, 2024

SO does not support fenced code blocks, so you need to indent by 4 spaces, and you can use the output format rmarkdown::md_document.

from reprex.

jennybc avatar jennybc commented on June 18, 2024

reprex does already do this, using md_document as @yihui points out. Request venue = "so", like so:

library(reprex)
so_md <- reprex({
  x <- 1:4
  y <- 2:5
  x + y
}, venue = "so")
writeLines(so_md)
#> <!-- language-all: lang-r -->
#> <br/>
#> 
#>     x <- 1:4
#>     y <- 2:5
#>     x + y
#>     #> [1] 3 5 7 9

Note the output you want (SO-ready markdown) should also be waiting on your clipboard after this little exercise.

I am tickled that I just used reprex to make a reprex, formatted for GitHub, demonstrating formatting of StackOverflow. META.

from reprex.

jennybc avatar jennybc commented on June 18, 2024

But, @baptiste, back to your title. reprex takes R code as input, not Rmd. I think that's the right call, because these little snippets are going to be mostly R code. You can still include prose, by prefixing with #'. The examples and README show this. When I use it on GitHub, I often write the prose part of my comment normally, then paste the reprex result in.

from reprex.

baptiste avatar baptiste commented on June 18, 2024

from reprex.

jennybc avatar jennybc commented on June 18, 2024

OK I will close for now, but keep this in mind.

I think if you've already psyched yourself up to write Rmd, a workflow helper like reprex isn't so relevant. Because you've already done most of the busy work that reprex handles anyway! The other 2 things it brings to the table then are:

  • upload.fun defaulting to imgur upload, as @baptiste points out
  • putting Markdown on the clipboard

from reprex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.