Linked Questions

Popular Questions

Getting document type that is knitted in knitr

Asked by At

I'm using code externalization in knitr. I have an myRcode.R file that includes codes and I have two kinds of reports I want to produce. One latex file (myLatexFile.RNW) and one html file (myHtmlFile.RMD). Both are calling chunks from the myRcode.R file. I want to get different outputs depending on the extension that calls the chunk.

Right now, my solution is this something like this:

library(stringr)
if (str_sub(current_input(),-3,-1) == "Rmd") {
  cat("HTML file...")
} else if (str_sub(current_input(),-3,-1) == "Rnw") 
  cat("LATEX file...")

But there should be a native function that gets the file type within the knitr. I couldn't find it. Is there such function in knitr?

Related Questions