texi2dvi()在使用LaunchControl运行.Rnw脚本时出错

时间:2022-11-08 01:08:11

I'm trying to compile a knitr script on a timer using LaunchControl (a launchd GUI for scheduling cron-like jobs on OSX).

我正在尝试用LaunchControl(在OSX上为cron一样的工作安排一个launchd GUI)在计时器上编译一个knitr脚本。

I have a dispatcher.R script that does this:

我有一个调度程序。这样做的R脚本:

#!/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:

当我在RStudio my_script中交互式地运行它时。Rnw伟大的工作。我得到所需的PDF输出。然而,当launchd运行分派器时。我得到这个错误的R脚本:

Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet, : Running 'texi2dvi' on 'my_script.tex' failed. Execution halted

texi2dvi中的错误(file = file, pdf = TRUE, clean = clean, quiet = quiet,: run 'texi2dvi' on 'my_script。特克斯的失败。停止执行

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?

生成.tex文件,但是它不会编译。我认为这是我的乳胶安装路径的问题,但是因为它使用的是knit2pdf()我不确定。有什么问题?


Still working on this. Updates:

还在研究这个。更新:

  • No .log file gets produced with knit2pdf() via LaunchControl, but I get a .tex file and /figure folder.

    使用knit2pdf()通过LaunchControl生成的不是.log文件,而是.tex文件和/figure文件夹。

  • I updated MacTex and also tried a minimal example of an empty document and I got the same error about texi2dvi.

    我更新了MacTex并尝试了一个最小的空文档示例,我得到了关于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.
  • 当我运行knit2pdf(“my_script。使用LaunchControl,输出=“my_script.tex”,然后返回RStudio并运行texi2dvi(“my_script”)。然后我得到了想要的结果。
  • 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
  • 在Sierra上,my_script_latex_pkg(“frame”,system)中还有一个错误。文件(“misc”、“陷害。):无法找到“框”的乳胶包装;会使用knitr的副本吗
  • I tried Sys.setenv(PATH = paste(Sys.getenv("PATH"),"/usr/texbin",sep=":")) and it didn't help.
  • 我试着系统。setenv(PATH = paste) (Sys.getenv(PATH)),“/usr/texbin”,sep=":"),它没有帮助。
  • Running $ Rscript dispatcher.R from the command line works just fine. The PDF compiles.
  • 运行$ Rscript调度员。命令行中的R可以正常工作。PDF编译。
  • Running a bash script with Rscript dispatcher.Rin LaunchControl does not work; same error about texi2dvi.
  • 使用Rscript调度程序运行bash脚本。发射控制不起作用;关于texi2dvi同样的错误。

1 个解决方案

#1


2  

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.

要使用LaunchControl来运行一个. rnw文件,在同一个目录中创建以下文件。然后,运行*。调度程序中的sh脚本。瞧!我在原来的帖子中遇到的问题是LaunchControl没有(默认情况下)读取~/。bash_profile,因此将路径变量添加到.sh脚本将解决此问题。

1) Your *.Rnw script

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

这是任何可以从RStudio编译的knitr脚本。

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.

确保您拥有通往LaTeX安装的路径变量。

#! /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).

该解决方案适用于OSX Yosemite 10.10.5上的R版本3.3.2(2016-10-31)。

#1


2  

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.

要使用LaunchControl来运行一个. rnw文件,在同一个目录中创建以下文件。然后,运行*。调度程序中的sh脚本。瞧!我在原来的帖子中遇到的问题是LaunchControl没有(默认情况下)读取~/。bash_profile,因此将路径变量添加到.sh脚本将解决此问题。

1) Your *.Rnw script

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

这是任何可以从RStudio编译的knitr脚本。

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.

确保您拥有通往LaTeX安装的路径变量。

#! /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).

该解决方案适用于OSX Yosemite 10.10.5上的R版本3.3.2(2016-10-31)。