[R] Open graphics device within sourced script?

David Winsemius dwinsemius at comcast.net
Mon May 6 02:23:25 CEST 2013


Cross-posting to r-help is not appropriate. (This is especially important when the answer was to be found in the R-FAQ.)  Please wait for an answer on SO if you choose to post there first. (Or if you have chosen to ignore this request, then at least have the courtesy to post a SOLVED notice here so people know that it has already been answered there.)

On May 5, 2013, at 4:34 PM, Richard Blissett 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
> 
> -- 
> Richard Blissett
> 
> Eco-Tip: Before printing, please consider whether you really need to have
> this email on paper.

Mailing List Courtesy-tip: Please learn to post in plain text.

> 	[[alternative HTML version deleted]]


--
David Winsemius
Alameda, CA, USA



More information about the R-help mailing list