[Rd] savePlot() no longer automatically adds an extension to the filename.

Duncan Murdoch murdoch at stats.uwo.ca
Tue Jun 3 21:08:08 CEST 2008


On 6/3/2008 11:22 AM, S Ellison wrote:
> Plaintive squeak: Why the change? 
> 
> Some OS's and desktops use the extension, so forgetting it causes
> trouble. The new default filename keeps a filetype (as before) but the
> user now has to type a filetype twice (once as the type, once as
> extension) to get the same effect fo rtheir own filenames. And the
> extension isn't then checked for consistency with valid file types, so
> it can be mistyped and saved with no warning. Hard to see the advantage
> of doing away with it...
> 
> Suggestion: Revert to the previous default (extension as type) and
> include an 'extension' in the parameter list so that folk who don't want
> it can change it and folk who did want it get it automatically.
> 
>  
> The code would then look something like 
> 
> savePlot<-function (filename = "Rplot", 
> 	type = c("wmf", "emf", "png", "jpg", "jpeg", "bmp", "tif",
> "tiff", "ps", "eps", "pdf"),
> 	device = dev.cur(), 
> 	restoreConsole = TRUE,
> 	extension)   #Added extension
> {
>     type <- match.arg(type)
>     if(missing(extension)) 
>            extension <- type	         ##added
>     devlist <- dev.list()
>     devcur <- match(device, devlist, NA)
>     if (is.na(devcur)) 
>         stop("no such device")
>     devname <- names(devlist)[devcur]
>     if (devname != "windows") 
>         stop("can only copy from 'windows' devices")
>     if (filename == "clipboard" && type == "wmf") 
>         filename <- ""
>       else
>         fullname <- paste(filename, extension,
> sep=ifelse(extension=="","",".") )  ##added
>     invisible(.External(CsavePlot, device, fullname, type,
> restoreConsole))            ##Modded
> }
> 
> Steve E
> 
> PS Yes, I took a while to upgrade from 2.6.x. Otherwise I'd have
> squeaked the day I upgraded - like I just did - 'cos I use savePlot a
> LOT.

Another way to avoid surprises like this is to pay attention to the 
daily announcements of changes.  This one was announced back in February:

http://developer.r-project.org/blosxom.cgi/R-devel/CHANGES/2008/02/26#c2008-02-26

Personally, I would have chosen to add an extension if the name 
contained no dot, but I didn't make this change, and don't really see a 
problem with it.  However, if you want to submit a patch that does this 
(including changes to src/library/grDevices/R/windows/windows.R, 
src/library/grDevices/man/windows/savePlot.Rd, and to 
src/gnuwin32/CHANGES) before Friday, I'll commit it.

Duncan Murdoch



More information about the R-devel mailing list