为什么(或者)为RSCRIPT(或利特勒)除R CMD批好? [英] Why (or when) is Rscript (or littler) better than R CMD BATCH?
问题描述
我自动化一些webscraping与研究
在的cron
有时我用研究CMD批
有时我用 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(如这或<一个href=\"http://stackoverflow.com/questions/14167178/passing-command-line-arguments-to-r-cmd-batch\">this)似乎 RSCRIPT
是preferred到研究CMD批
。
But reading the answers to some questions here in SO (like this or this) it seems that Rscript
is preferred to R CMD BATCH
.
所以我的问题是:
-
除了这个事实,语法是有点不同的,
研究CMD批
节省了.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?
当我应该preFER一个比另一个?更具体地说,在上面提到的的cron
的工作,就是其中之一preferred?
When should I prefer one over another? More specifically, in the cron
job above mentioned, is one of them preferred?
我没有使用尚未利特勒
,它是如何从两个不同的 RSCRIPT
和研究CMD批
?
I have not used yet littler
, how is it different from both Rscript
and R CMD BATCH
?
推荐答案
研究CMD批
就是我们几年前了。它使I / O非常辛苦和叶隐藏文件。
R CMD BATCH
is all we had years ago. It makes i/o very hard and leaves files behind.
事情RSCRIPT好转,先用利特勒,然后过。既可以用于'认领'线,如
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 ...]\n")
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)
和就像卡尔,我有cronjobs调用类似 - [R脚本。
And just like Karl, I have cronjobs calling similar R scripts.
的在2015年11月4日编辑:的截至上周,的现在利特勒也是在CRAN 。
这篇关于为什么(或者)为RSCRIPT(或利特勒)除R CMD批好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!