Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rscript在终端中的收益率为;错误:RStudio未运行“;_R_Command Line Interface_Rstudio - Fatal编程技术网

Rscript在终端中的收益率为;错误:RStudio未运行“;

Rscript在终端中的收益率为;错误:RStudio未运行“;,r,command-line-interface,rstudio,R,Command Line Interface,Rstudio,和往常一样,我已经使用了一段时间预装了R的Rstudio。几天前,我决定在terminal/CLI中尽我所能地运行所有东西,因为一些GUI/IDE不断地崩溃,在我看来,用vim完成我的工作就足够了。我在谷歌上搜索并尝试运行一个R脚本,我以前使用Rstudio运行,现在使用Rscript。我还向PATH中添加了R和Rscript,向文件中运行了chmod+x,向R文件中添加了shebang,但我得到的消息是: Error: RStudio not running Execution halted

和往常一样,我已经使用了一段时间预装了R的Rstudio。几天前,我决定在terminal/CLI中尽我所能地运行所有东西,因为一些GUI/IDE不断地崩溃,在我看来,用vim完成我的工作就足够了。我在谷歌上搜索并尝试运行一个R脚本,我以前使用Rstudio运行,现在使用Rscript。我还向PATH中添加了R和Rscript,向文件中运行了
chmod+x
,向R文件中添加了shebang,但我得到的消息是:

Error: RStudio not running
Execution halted
那么,我做错了什么?如果我还没有尝试在命令行中使用这个脚本,为什么Rstudio会尝试运行这个脚本呢?我删除了几乎所有的代码,只留下一行,调用了另一个R脚本,从而清除了环境:

#!/usr/bin/Rscript

# Clears everything
source("cleanAll.R")
cleanAll.R代码:

rm(list = ls())     # Clears global environment
cat("\014")         # Clears the console
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
graphics.off()

您正在尝试使用{rstudioapi}包

除非您处于交互式RStudio会话中,否则无法使用此软件包。因此出现错误
错误:RStudio未运行

您正在尝试获取工作目录吗?您应该使用
getwd()

如果是这样的话

删除.R文件中的setwd()命令并运行,它工作得很好

似乎您正试图在rscript中运行一个必须在RStudio中调用的函数。这个脚本做什么?不完全是一个函数,实际上是同一目录中的另一个文件。这就是所谓的Rstudio吗?如果不运行Rstudio,则无法使用source命令?我在问题中添加了脚本代码。这并没有提供问题的答案。若要评论或要求作者澄清,请在其帖子下方留下评论。-Hi@EneaDume我澄清了作者的答案,因为在他的代码中使用了一个名为setwd()的命令,如果他删除该命令,代码工作正常,不会出现“Error:RStudio not running”这个错误。谢谢