[R] Open graphics device within sourced script?

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Mon May 6 02:48:11 CEST 2013


Believe it or not, this is FAQ 7.16 (consider also FAQ 7.22).
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

Richard Blissett <rsl.bliss at gmail.com> wrote:

>Hello all, I am having the weirdest issue that I don't know how to get
>around.
>
>I am using R, and I am sourcing another script within one master
>script.
>Within the sourced script, I have code that looks like the following:
>
>pdf("Figs/bar_gni.pdf")
>m1table$Country1 <- reorder(m1table$Country, m1table$GNIpc2005)
>ggplot(m1table, aes(y=GNIpc2005, fill=Level)) +
>  geom_bar(aes(x=Country1), data=m1table, stat="identity") +
>  coord_flip() +
>  ggtitle("GNI Per Capita, 2005") +
>  xlab("Country") +
>  ylab("GNI per capita, Atlas method (current US$)")
>dev.off()
>
>The important part, if I'm correct, is that I'm opening a pdf graphics
>device, making a plot, and then closing the device.
>
>When I run the source script itself (by opening the script), this all
>works
>just fine. However, when I source it, none of my graphs are outputted.
>It
>seems to create the files, but it just creates blank files.
>
>Any feedback would be greatly appreciated.
>Richard



More information about the R-help mailing list