Reputation: 4109
I'm trying to compile a knitr script on a timer using LaunchControl (a launchd GUI for scheduling cron-like jobs on OSX).
I have a dispatcher.R script that does this:
#!/Library/Frameworks/R.framework/Resources/Rscript
library("knitr")
setwd("~/somedirectory")
knit2pdf("my_script.Rnw", output= "my_script.tex")
When I run it interactively from in RStudio, my_script.Rnw works great. I get the desired PDF output. However, when launchd runs the dispatcher.R script I get this error:
Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet, : Running 'texi2dvi' on 'my_script.tex' failed. Execution halted
The .tex file gets generated, but then it doesn't compile. I a would say it was problem with my LaTeX installation path, but since it works using knit2pdf()
I'm not sure. What could be the issue?
Still working on this. Updates:
No .log file gets produced with knit2pdf()
via LaunchControl, but I get a .tex file and /figure folder.
I updated MacTex and also tried a minimal example of an empty document and I got the same error about texi2dvi.
knit2pdf("my_script.Rnw", output = "my_script.tex")
using LaunchControl and then go back to RStudio and run texi2dvi("my_script.tex", pdf = TRUE)
, then I get the desired outcome. In my_script_latex_pkg("framed", system.file("misc", "framed.sty", package = "knitr")) : unable to find LaTeX package 'framed'; will use a copy from knitr
Sys.setenv(PATH = paste(Sys.getenv("PATH"),"/usr/texbin",sep=":"))
and it didn't help.$ Rscript dispatcher.R
from the command line works just fine. The PDF compiles. Rscript dispatcher.R
in LaunchControl does not work; same error about texi2dvi. Upvotes: 4
Views: 2333
Reputation: 4109
To run a .Rnw file using LaunchControl for task scheduling, create the following files in the same directory. Then, run the *.sh script in the scheduler. Voila! The problem I was encountering in my original post was the LaunchControl doesn't (by default, at least) read ~/.bash_profile, so adding the PATH variable into the .sh script resolves this.
This is any knitr
script that you can compile without issue from RStudio.
#!/Library/Frameworks/R.framework/Resources/Rscript
library("knitr")
setwd("~/some_directory")
knit2pdf("yourscript.Rnw", output = "yourscript.tex")
Make sure that you have the PATH variable to your LaTeX installation.
#! /bin/bash
PATH="/usr/texbin:${PATH}"
export PATH
Rscript yourscript_dispatcher.R
This solution works on OSX Yosemite 10.10.5 on R version 3.3.2 (2016-10-31).
Upvotes: 4