在windows命令行上执行的Rscript不';没有任何结果
我正在尝试在windows cmd上运行非常简单的Rscript文件 我尝试测试的Rscript如下所示:在windows命令行上执行的Rscript不';没有任何结果,r,windows,cmd,R,Windows,Cmd,我正在尝试在windows cmd上运行非常简单的Rscript文件 我尝试测试的Rscript如下所示: setwd("C:\Users\Lily\Tutorial0") Product <-function(a,b) { p <- a*b return(p) } result <- Product(10,0.4); print("Calculating the result...") print(result); 如何在
setwd("C:\Users\Lily\Tutorial0")
Product <-function(a,b)
{
p <- a*b
return(p)
}
result <- Product(10,0.4);
print("Calculating the result...")
print(result);
如何在window cmd上显示结果
令人惊讶。我刚刚用你的代码尝试了同样的方法,效果非常好,不过我已经删除了
setwd
部分。在RStudio中运行脚本时会发生什么?b) 使用cat
而不是print
和c)addflush.console()
?另外,在c:\Users\Lily
的命令提示符中,您可以编写类型Tutorial0.R
并发布结果的屏幕截图吗?@coffeinjunky a)在R studio中,它工作正常。b、 c)我用Tutorial1的名字试过,但没有成功。我在帖子中添加了“第二次尝试”的结果,我无法重现,但它也给我留下了深刻的印象,你在截图中试图描绘的东西无法工作,必须抛出错误,但你说它在RStudio中运行良好。
C:\Users\Lily>Rscript Tutorial0.R
C:\Users\Lily>Rscript
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 --no-echo --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