0

I have a portion of code that "sounds" like:

bla bla () <- bla R stuff bla
...
p <- readline()
cat("This is the amazing parameter ",p)

It obvioulsy works on the command line. The problem is that Rstudio have issues about with the interactivity.

So, there exists a way in which R understand if you're typing from a command line or from Rstudio. Something like:

bla bla () <- bla R stuff bla
...
if(RstudioInput() == true){
    p <- "param"
} else {
   p <- readline()
}
cat("Again, this is the awesome parameter ",p)

Summarizing, I need to know both if the code is running from Rstudio and also if the code is running from the command-line.

Andrea Ianni
  • 829
  • 12
  • 24

1 Answers1

1

Use Sys.getenv("RSTUDIO") it returns "1" when running RStudio and "" when not running RStudio.

Thierry
  • 18,049
  • 5
  • 48
  • 66