Nancy
Nancy

Reputation: 4109

texi2dvi() error when running a .Rnw script with LaunchControl

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:

Upvotes: 4

Views: 2333

Answers (1)

Nancy
Nancy

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.

1) Your *.Rnw script

This is any knitr script that you can compile without issue from RStudio.

2) A *.R script

#!/Library/Frameworks/R.framework/Resources/Rscript
library("knitr")
setwd("~/some_directory")
knit2pdf("yourscript.Rnw", output = "yourscript.tex")

3) A *.sh script

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

Related Questions