How to call linux terminal code from R script

自古美人都是妖i 提交于 2019-12-12 04:15:16

问题


My question is:

How can I call a Linux Terminal inside a R script?

I know it can be a silly question... my R code is here:

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

after the download, I had to convert that file using a code from terminal... but I need this to be automatic. The converter code is this:

source activate ncl_stable
cd /home
ncl_convert2nc myfile.grb2

Googling I saw that Linux Terminal uses C++. I know there is a package to run C++ codes in to R, Rcpp, but it works like the linux terminal?


回答1:


This will do the trick:

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

You can find more information here or here.



来源:https://stackoverflow.com/questions/44235693/how-to-call-linux-terminal-code-from-r-script

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