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

巧了我就是萌 提交于 2019-12-01 07:12:29

问题


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.

  • When I run 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.
  • The problem reproduces on Sierra and Yosemite
  • On Sierra there is an additional error about 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
  • I tried Sys.setenv(PATH = paste(Sys.getenv("PATH"),"/usr/texbin",sep=":")) and it didn't help.
  • Running $ Rscript dispatcher.R from the command line works just fine. The PDF compiles.
  • Running a bash script with Rscript dispatcher.Rin LaunchControl does not work; same error about texi2dvi.

回答1:


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).



来源:https://stackoverflow.com/questions/41731493/texi2dvi-error-when-running-a-rnw-script-with-launchcontrol

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!