首页 > 解决方案 > 在 Windows 命令行上执行的 Rscript 不显示任何结果

问题描述

我正在尝试在 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);

为了使用命令Rscript,我在 PATH 变量中添加了 Rscript.exe 和 R.exe 的路径,因为我在 D 驱动器上安装了 R。

然而,Rscript 命令似乎工作,但我想要的结果(即“计算结果....4)没有出来。实际上除了下一行输入之外什么也没出现。

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

如何在窗口 cmd 上显示结果?

命令行 第二次尝试

标签: rwindowscmd

解决方案


推荐阅读