使用 System() 从 R 脚本调用 Python 命令

Invoke Python command from R script with System()

在我的 R 脚本中,我必须执行一个外部 Python 脚本并且我会使用 System() function.

system("python -m premailer -f daily-report.html -o
ready-weekly-report.html")

但是在 R 控制台中 运行 之后,这就是我得到的

/usr/bin/python: No module named premailer

如果我 运行 来自终端的 python 命令一切正常。

编辑

这就是我解决这个问题的方法。

Adding the following line to the end of that file, showed me the correct path in Rstudio after restarting my R kernel:

.Internal(Sys.setenv("PATH", paste("/usr/local/bin", Sys.getenv("PATH"), sep=":")))