[R] savePlot for Mac and / or Linux?

James W. MacDonald jmacdon at med.umich.edu
Mon Dec 7 15:23:46 CET 2009


Hi Christophe,

No, there isn't anything close to savePlot() on either Linux or MacOS. 
But the difference is that savePlot() is used to save something that has 
already been plotted. Since your function appears to be intended to give 
the user the ability to save something that has yet to be plotted, you 
could simply use a switch() statement in the body of your function:


switch(type, pdf = {
pdf("plotname.pdf")
plot(<something>)
dev.off()
},
jpeg = {
jpeg("plotname.jpg")
plot(<something>)
dev.off()
},
png = {
png("plotname.png")
plot(<something>)
dev.off()
})

You can also plot things first and use recordPlot() and replayPlot() to 
emulate savePlot(). In addition, you can get tricky and check to see if 
the version of R being used is capable of doing a particular plot type 
using capabilities() and then trapping errors where the end user wants 
to create a plot that their R installation won't do.

Best,

Jim



Christophe Genolini wrote:
> Hi all,
> 
> In the package rtlu, I use the function savePlot. It is convenient since 
> it let the user decide in which graphic format he wants his graph to be 
> export.
> But when I run R CMD check, I get the following message :
> 
>>  rtlu(V1,fileOutput="First.tex",textBefore="\\section{Variable 1 to 
> 3}",graphName="V1")
> Error in savePlot(filename = nomBarplot, type = type) : can only copy 
> from 'windows' devices
> Calls: rtlu ... r2lUniv -> r2lUniv.factor -> r2lBarplot -> savePlot
> Execution halted
> 
> I guess this is a compatibility problem with Linux/Mac? Is there 
> something close to savePlot for Mac / Linux?
> 
> Christophe
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
James W. MacDonald, M.S.
Biostatistician
Douglas Lab
University of Michigan
Department of Human Genetics
5912 Buhl
1241 E. Catherine St.
Ann Arbor MI 48109-5618
734-615-7826
**********************************************************
Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues 




More information about the R-help mailing list