如何从 R 脚本调用 linux 终端代码

How to call linux terminal code from R script

我的问题是:

如何在 R 脚本 中调用 Linux 终端?

我知道这可能是个愚蠢的问题...我的 R 代码在这里:

download.file('https://some.dir,
              destfile = '/home/myfile.grb2',method='auto',quiet = FALSE,
              mode="wb", cacheOK = TRUE)

下载后,我不得不使用来自终端的代码转换该文件...但我需要它是自动的。转换器代码是这样的:

source activate ncl_stable
cd /home
ncl_convert2nc myfile.grb2

谷歌搜索我看到 Linux 终端 使用 C++。我知道有一个 运行 C++ 代码到 R 的包,Rcpp,但它像 linux 终端一样工作?

这样做就可以了:

system(paste0("source activate ncl_stable;cd /home;ncl_convert2nc myfile.grb2"))

您可以找到更多信息here or here