终端中的 Rscript 产生 "Error: RStudio not running"

标签 r command-line-interface rstudio

像往常一样,我一直在使用预装 R 的 Rstudio。几天前,我决定在终端/CLI 中运行所有我能运行的东西,因为一些 GUI/IDE 不断地崩溃,在我看来,在 vim 中做我的事情就足够了。我用谷歌搜索并尝试运行我曾经用 Rstudio 运行的 R 脚本,现在使用 Rscript。我还将 R 和 Rscript 添加到 PATH,运行 chmod +x到文件,将shebang添加到R文件中,但我得到的消息是这样的:

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 session 中,否则您无法使用此包。因此错误 Error: RStudio not running .

您是否正在尝试获取工作目录?您应该使用 getwd()如果是这种情况。

关于终端中的 Rscript 产生 "Error: RStudio not running",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48632701/

相关文章:

multithreading - 如何使用 CLI 工具确定 Wildfly 11 上哪些线程使用了大量 CPU?

r - 针织簇绒交叉引用失败

php - Slim 3 控制台执行 cron

r - Rcpp 中的 na.locf 和 inverse.rle

c++ - 如何在声明后将 NumericVector 初始化为特定大小?

regex - 有人可以准确解释这些 gsub 参数吗?

amazon-web-services - mturk 的多个地点资格和接受率不起作用

r - 如何以 Shiny 的方式内嵌显示小部件

r - 如何将弹出式帮助文本添加到 RStudio 中用户创建的包中的函数?

sql - 等同于带data.table的sql笛卡尔查询