为什么(或何时)Rscript(或更小)比R CMD BATCH 更好? [英] Why (or when) is Rscript (or littler) better than R CMD BATCH?
问题描述
我在 cron
中使用 R
自动化一些网页抓取,有时我使用 R CMD BATCH
有时我使用 Rscript代码>.
I am automating some webscraping with R
in cron
and sometimes I use R CMD BATCH
and sometimes I use Rscript
.
决定使用哪个我主要关注是否需要 .Rout
文件.
To decide which one to use I mainly focus if I want the .Rout
file or not.
但是在 SO 中阅读某些问题的答案(例如 this 或 this) 似乎 Rscript
优于 R CMD BATCH
.
But reading the answers to some questions here in SO (like this or this) it seems that Rscript
is preferred to R CMD BATCH
.
所以我的问题是:
除了语法有点不同,
R CMD BATCH
保存了一个.Rout
文件,而Rscript
没有,两者的主要区别是什么?
Besides the fact that the syntax is a little different and
R CMD BATCH
saves an.Rout
file whileRscript
does not, what are the main differences between the two of them?
我什么时候应该更喜欢一个?更具体地说,在上面提到的 cron
作业中,是否首选其中之一?
When should I prefer one over another? More specifically, in the cron
job above mentioned, is one of them preferred?
我还没用过little
,它和Rscript
和R CMD BATCH
有什么区别?
I have not used yet littler
, how is it different from both Rscript
and R CMD BATCH
?
推荐答案
R CMD BATCH
是我们多年前的全部.它使 i/o 变得非常困难并留下文件.
R CMD BATCH
is all we had years ago. It makes i/o very hard and leaves files behind.
事情变得更好了,首先是 littler,然后是 Rscript.两者都可以用于shebang"行,例如
Things got better, first with littler and then too with Rscript. Both can be used for 'shebang' lines such as
#!/usr/bin/r
#!/usr/bin/Rscript
并且两者都可以与诸如 getopt 和 optparse 之类的包一起使用 --- 允许您编写可以充当命令的适当 R 脚本.如果有几十个,从这样的简单开始,我可以将其称为 install.r pkga pkgb pkgc
并且将从命令行为我安装所有三个及其依赖项),而不会占用R 提示:
and both can be used with packages like getopt and optparse --- allowing you to write proper R scripts that can act as commands. If have dozens of them, starting with simple ones like this which I can call as install.r pkga pkgb pkgc
and which will install all three and their dependencies) for me from the command-line without hogging the R prompt:
#!/usr/bin/env r
#
# a simple example to install one or more packages
if (is.null(argv) | length(argv)<1) {
cat("Usage: installr.r pkg1 [pkg2 pkg3 ...]
")
q()
}
## adjust as necessary, see help('download.packages')
repos <- "http://cran.rstudio.com"
## this makes sense on Debian where no packages touch /usr/local
lib.loc <- "/usr/local/lib/R/site-library"
install.packages(argv, lib.loc, repos)
和 Karl 一样,我也有调用类似 R 脚本的 cronjobs.
And just like Karl, I have cronjobs calling similar R scripts.
于 2015-11-04 截至上周,littler 现在也在 CRAN 上.
这篇关于为什么(或何时)Rscript(或更小)比R CMD BATCH 更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!