Here is the code to reproduce my problem:
library(ggplot2)
data <- data.frame(randomnums <- rnorm(50,100,200))
plot1 <- ggplot(data, aes(randomnums)) + geom_histogram()
print(plot1)
ggsave(plot1, filename="figures/plot1.pdf", width=5, height=3)
plot2 <- ggplot(data, aes(randomnums)) + geom_histogram()
print(plot2)
ggsave(plot2, filename="figures/plot2.pdf", width=5, height=3)
plot3 <- ggplot(data, aes(randomnums)) + geom_histogram()
print(plot3)
ggsave(plot3, filename="figures/plot3.pdf", width=5, height=3)
If each line of the above code is run line by line and waiting for each command to complete, then everything works fine. However, if I select all and run, things break down:
- the first pdf file (plot1.pdf) that is saved will have a file size of 0k, and cannot be opened until I close my rsession (via rstudio)
- My plots are not printed onto the screen. In RStudio, I there are no plots in the "plots" tab.
If I restart rstudio, everything will work fine again if I run the code line by line. Am I missing a command to make sure the code can be run as an entire selection?
EDIT: As requested - my session info.
> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_0.9.3.1
loaded via a namespace (and not attached):
[1] colorspace_1.2-1 dichromat_2.0-0 digest_0.6.3 grid_2.15.2 gtable_0.1.2 labeling_0.1
[7] lavaan_0.5-12 MASS_7.3-23 munsell_0.4 plyr_1.8 proto_0.3-10 RColorBrewer_1.0-5
[13] reshape2_1.2.2 scales_0.2.3 stats4_2.15.2 stringr_0.6.2 tools_2.15.2
EDIT: It was discovered that this only breaks in RStudio. It works fine in RGui.