I got the below function from Prof's website: http://diskworld.wharton.upenn.edu/~foster/teaching/471/sweave-intro.pdf

The said function is meant for converting sweave (.Rnw) into PDF.

But when i run it on my machine, I get this error:

Error in match.arg(options$results, c("verbatim", "tex", "hide")) :

'arg' should be one of "verbatim", "tex", "hide"


Sweatex  <- function(filename,extension='Rnw',
     command='pdflatex',silent=FALSE,preview=FALSE) {
  if (command=='latex') command='simpdftex latex --maxpfb'

  system(paste(path,command,' ',filename,sep=''),intern=silent)

  if (preview)
    system(paste(options('pdfviewer')[[1]],' ',filename,'.pdf',sep=''))

Could anyone throw some lights? Thanks, in advance.

Regards, Tharma

  • Perhaps the right place to ask this is in Cross Validated. But you might want to try Rstudio for your Sweave and knitr files. But even without Rstudio, you can compile your .Rnw file into pdf by running Sweave("yourfile.Rnw") in your R console and then running pdflatex yourfile in the terminal. There is this discussion in SO about efficient Sweave workflow too. – hpesoj626 Jul 24 '13 at 14:09

You can obtain directly a PDF typing outside of the R environment (in a Linux console, probably in Windows too) with this command:

 R CMD Sweave --pdf file.Rnw

Note that if the LaTeX code contain something that must be compiled twice (See What are the situations where you have to compile a document more than once? ) then you must avoid the --pdf option (at least for the final document) and compile the resulting file.tex with pdflatex as many times as needed.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.