Specifying the output path for knit2html

I am having trouble specifying the output path for the html generated by knit2html or its dependent functions. I would like to specify "outfile" in the call to knit2html (), but I get an error,

Error in knit2html (input = "test.Rmd", output = "test-abcd.html"):
'outfile' object not found

'output' is a markdownToHTML parameter that should work, I think. I can not find anywhere in the source where "outfile" is used.

This should reproduce my experience.

library(knitr) library(markdown) # a minimal example writeLines(c("```{r hello-random, echo=TRUE}", "rnorm(5)", "```"), "test.Rmd") # this works and outputs to test.html knit2html(input = "test.Rmd") # this generates the above error knit2html(input = "test.Rmd", output = "test-abcd.html") # breaking it down into two steps works in this simple case, # but not in my application. trying to diagnose that difference currently knit("test.Rmd") markdownToHTML("test.md", output="test-abcd.html") 

Can the information on the corresponding version be useful?

 sessionInfo() R version 3.0.0 (2013-04-03) Platform: x86_64-pc-linux-gnu (64-bit) other attached packages: [1] plyr_1.8 knitr_1.2 digest_0.6.3 markdown_0.5.4 xtable_1.7-1 reshape2_1.2.2 scales_0.2.3 ggplot2_0.9.3.1 data.table_1.8.8 
+6
source share
1 answer

Firstly, thanks for the very clear and reproducible question. If you look at the source code of the knit2html function, you can understand what the problem is:

 R> knit2html function (input, ..., envir = parent.frame(), text = NULL, quiet = FALSE, encoding = getOption("encoding")) { if (is.null(text)) { out = knit(input, envir = envir, encoding = encoding, quiet = quiet) markdown::markdownToHTML(out, outfile <- sub_ext(out, "html"), ...) invisible(outfile) } else { out = knit(text = text, envir = envir, encoding = encoding, quiet = quiet) markdown::markdownToHTML(text = out, ...) } } <environment: namespace:knitr> 

If the text argument is NULL (i.e. if you specify the file as input instead of a character vector), then this file is passed to the knit function, and the markdownToHTML function is called as follows:

 markdown::markdownToHTML(out, outfile <- sub_ext(out, "html"), ...) 

So, in this case, the output file name is generated by replacing the existing file name extension with html , and you cannot provide your own output file name as an argument.

+3
source

Source: https://habr.com/ru/post/943910/


All Articles