Motivation: I often want to paste the results of a quick analysis using R Markdown into a StackExchange site. This includes the R-tag on Stack Overflow, Cro
Although I'd still like to read other suggestions I hacked together this script using @Ramnath's answer as a starting point. It outputs a HTML fragment rather than Markdown.
Rscript -e 'rmd_file <- dir(pattern="rmd"); md_file <- sub("rmd", "md", rmd_file); html_file <- sub("rmd", "html", rmd_file); require(methods); require(knitr); require(markdown); opts_knit$set(upload.fun = imgur_upload); knit(rmd_file); markdownToHTML(md_file, html_file, options="fragment_only") '
rmd file in the working directory. I imagine that selecting the rmd file could be done in a more sophisticated way.knitr and markdown packages are installed.methods package needs to be loaded.The result looks pretty good. It overcomes the issue of excessive blank lines. However, the output is not markdown, which makes the result harder to edit.