Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rscript in terminal yields in "Error: RStudio not running"

I've been using for while Rstudio with R pre-installed, as usual. Some days ago I decided to run absolutely everything I can in the terminal/CLI, since some GUI/IDEs keep crashing over and over and doing my stuff in vim seem to me to be enough. I googled and tried to run a R script that I used to run with Rstudio, now using Rscript. I also added R and Rscript to PATH, ran chmod +x to the file, added the shebang to the R file, and yet the message that I get is this:

Error: RStudio not running
Execution halted

So, what am I doing wrong? Why does it seem Rstudio is trying to run this script if I haven't even tried to use it in the command line? I have erased almost all the code and left only one line, that calls another R script, which clears the environment:

#!/usr/bin/Rscript

# Clears everything
source("cleanAll.R")

cleanAll.R code:

rm(list = ls())     # Clears global environment
cat("\014")         # Clears the console
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
graphics.off()
like image 384
user260876 Avatar asked Jan 03 '23 20:01

user260876


1 Answers

You are trying to use the {rstudioapi} package.

You can't use this package unless you are in an interactive RStudio session. Hence the error Error: RStudio not running.

Are you trying to get the working directory? You should use getwd() if this is the case.

like image 153
Colin FAY Avatar answered Jan 05 '23 14:01

Colin FAY