JerryN
JerryN

Reputation: 2506

R run sweave (Rnw) file from an R script

I would like to run sweave from an R script. The Rnw file is in an Rnw directory just below my project directory. I tried this

system("Rnw/compilePDF.Rnw")

And got this response.

sh: Rnw/compilePDF.Rnw: Permission denied

The permissions on the .Rnw file are -rw-r--r-- but I suspect that is not the issue.

Upvotes: 2

Views: 1173

Answers (1)

JerryN
JerryN

Reputation: 2506

The solution is to include the following bits of code. The encoding is needed because Sweave default is ASCII and returns an error to this effect.

Sweave("Rnw/compilePDF.Rnw", encoding = "UTF-8")

The output of the command is

Writing to file compilePDF.tex
Processing code chunks with options ...

You can now run (pdf)latex on ‘compilePDF.tex’

To convert this to pdf use

tools::texi2pdf("Rnw/compilePDF.tex")

Upvotes: 2

Related Questions