0

Code where I have to explicitly decleare pdf to get even one page output into filesystem with RStudio, but failing to get two pages on the filesystem target

library("ggplot2")
library("datasets")

options(device="pdf") # https://stackoverflow.com/questions/6535927/how-do-i-prevent-rplots-pdf-from-being-generated
filename.pdf <- paste0(getwd(), "/", "Rplots", ".pdf", sep = "")
pdf(file=filename.pdf)

data(iris)
plot(iris)

dat.m <- data("mtcars")
print(head(dat.m)) 

ggplot(data=mtcars, aes(x=mpg, y=hp, colour=factor(cyl))) + geom_line() # https://stackoverflow.com/a/38278702/54964
# TODO Output nothing so wrong!

print(getwd())
print(warnings())
dev.off() # nenecssary with RStudio   

Output in RStudio: one page
Output in Rscript: two pages
Expected output: two pages

Prompt output in all where no errors

[1] "/home/masi/Workspace"
Warning message:
In sink() : no sink to remove

OS: Debian 9
RStudio: 1.0.143
R: 3.4.0

Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
  • 1
    I'm not quite sure what you are asking, but you need to use `print(ggplot(...` if in a script – user20650 Jul 16 '17 at 12:33
  • 1
    @user20650 You are right! Please, add it as an aswer because it is rigbt so I will not forget this anymore again. - - Is there any way to avoid many `print` commands there, like printing all figures lastly only once? – Léo Léopold Hertz 준영 Jul 16 '17 at 12:35
  • maybe relevant as well https://stackoverflow.com/questions/6675066/ggplots-qplot-does-not-execute-on-sourcing – user20650 Jul 16 '17 at 12:39

0 Answers0