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()
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With