0

Certain functions in R appear to behave slightly differently depending on whether a script is run in an interpreter or called from the command line. For instance, if I print certain types of plot objects from within the interpreter, they simply display on my screen, with no new files created. If I run the same script from the command line using Rscript ..., however, R will automatically save a .pdf of the plot, under the name Rplots.pdf in whatever my current working directory is. I find this unwanted creation of files undesirable.

Ideally, I'd like a way to encapsulate my print() commands in some kind of logical test that would check if the script is running from an interpreter. Alternatively, if there is some different way to use the print() function, or some alternative to it, that could avoid the creation of unwanted files, that would also be a satisfactory result.

See below for minimal working script:

# Rscript "Interpreter_Question.R"

library(ggplot2)

df <- data.frame(x=1:10, y=rnorm(10))
p1 <- ggplot(df, aes(x,y)) + geom_point()

print(p1)
Michael Ohlrogge
  • 10,559
  • 5
  • 48
  • 76

0 Answers0