从命令行运行R命令 [英] Run R command from command line
本文介绍了从命令行运行R命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以从命令行运行R命令?像
Is there a way to run an R command from the command line? Something like
$ R --run '1+1'
2
甚至是
$ Rscript < '1+1'
2
推荐答案
命令行选项 -e
正是这样做的.
The command line option -e
does exactly that.
Rscript.exe -e "1+1"
[1] 2
如果您仅运行不带参数的 RScript
,则会在您获得的帮助中明确说明:
It is clearly explained in the help which you get if you just run RScript
without parameters:
Usage: /path/to/Rscript [--options] [-e expr [-e expr2 ...] | file] [args]
--options accepted are
--help Print usage and exit
--version Print version and exit
--verbose Print information on progress
--default-packages=list
Where 'list' is a comma-separated set
of package names, or 'NULL'
or options to R, in addition to --slave --no-restore, such as
--save Do save workspace at the end of the session
--no-environ Don't read the site and user environment files
--no-site-file Don't read the site-wide Rprofile
--no-init-file Don't read the user R profile
--restore Do restore previously saved objects at startup
--vanilla Combine --no-save, --no-restore, --no-site-file
--no-init-file and --no-environ
'file' may contain spaces but not shell metacharacters
Expressions (one or more '-e <expr>') may be used *instead* of 'file'
See also ?Rscript from within R
这篇关于从命令行运行R命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文