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

S Ellison S.Ellison at lgc.co.uk
Tue Jun 3 17:22:45 CEST 2008


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.



*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}



More information about the R-devel mailing list