pipe - How to knit directly to R object? -


i'd store knit()ted document directly in r r object, character vector.

i know can knit()ing tempfile() , import result, so:

library(knitr) library(readr) ex_file <- tempfile(fileext = ".tex") knitr::knit(text = "foo", output = ex_file) knitted_obj <- readr::read_file(ex_file) knitted_obj 

returns

# [1] "foo\n" 

as intended.

is there way without using tempfile() , directly "piping" result vector?


why on earth want this, ask?

  • *.tex string programmatically saved disc, , rendered pdf later. reading rendered *.tex disc in downstream functions make code more complicated.
  • caching whole lot easier, , moving cache different machine.
  • i scared of side effects in general , file system shenanigans across machines/oses in particular. want isolate few (print(), save(), plot()) functions possible.

does make me bad (or ocd) r developer?

it should straightforward single line this:

knitted_obj = knitr::knit(text = "foo") 

you may want read page ?knitr::knit again know returns.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -