RMarkdown integration

meik michalke meik.michalke at uni-duesseldorf.de
Wed Apr 18 15:05:31 UTC 2018


hi,

i've -- once more -- looked a bit into options for integrating RMarkdown into 
RKWard.

this one uses the packages knitr and markdown to produce the older v1 format 
and finally HTML. i'm also using "text" (which expects the markdown code as a 
character vecor) versus "input" (which expects a file name), so that the 
resulting object contains the HTML code in a character vector as well:

 library(knitr)
 library(markdown)
 txt <- knitr::knit2html(text="<RMarkdown code ...>")

of course you can also work on files and get files as a result.

for the newer v2 documents, the alternative is render() from the rmarkdown 
package 

 library(knitr)
 library(rmarkdown)
 rmarkdown::render("some.Rmd"))

it always writes files, and you must disable "theme" and "highlight" in the 
.Rmd's header to get small files (without that, a payload of ~700kb of 
JavaScript is added to every output document automatically).

a third and probably the most versatile option is using the pandoc() wrapper, 
because that allows you to convert the RMarkdown document into various useful 
formats:

 library(knitr)
 pandoc(input=knit("some.Rmd", output="some.md"), format="html")
 # or OpenDocument
 pandoc(input=knit("some.Rmd", output="some.md"), format="odt")
 # or PDF via LaTeX
 pandoc(input=knit("some.Rmd", output="some.md"), format="latex")
 # ...


we've been thinking about replacing the current output handling for some years 
now. well, a radical new approach for a future version of RKWard could be that 
plugins don't generate R code and use R2HTML for output, but a short RMarkdown 
document which includes the generated R code. RKWard would then call one of 
the functions above to generate the output or instant previews. the output 
file could also be RMarkdown and be rendered instantly (a general "switch 
view" option for RMarkdown files would be neat and shouldn't be too much 
work), but that would of course change the nature of the document. it wouldn't 
be a static source of past calculations, but dynamically change or even fail 
to render when data files are removed. keeping one file for months would not 
make sense any longer, such a file would better be stored with the data or 
project.

that's my thoughts so far.


viele grüße :: m.eik

-- 
  dipl. psych. meik michalke
  institut f"ur experimentelle psychologie
  abt. f"ur diagnostik und differentielle psychologie
  heinrich-heine-universit"at d-40204 d"usseldorf
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/rkward-devel/attachments/20180418/eb40e0a8/attachment.sig>


More information about the rkward-devel mailing list