S Ellison
2008-Jun-03 15:22 UTC
[Rd] savePlot() no longer automatically adds an extension to the filename.
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}}
Gabor Grothendieck
2008-Jun-03 16:02 UTC
[Rd] savePlot() no longer automatically adds an extension to the filename.
Not sure if this is sufficient but note that if you leave the filename off entirely then the extension does default to the type. savePlot() # wmf savePlot(type = "jpg")> args(savePlot)function (filename = paste("Rplot", type, sep = "."), type = c("wmf", "emf", "png", "jpg", "jpeg", "bmp", "tif", "tiff", "ps", "eps", "pdf"), device = dev.cur(), restoreConsole = TRUE) https://svn.r-project.org/R/trunk/src/library/grDevices/R/windows/windows.R On Tue, Jun 3, 2008 at 11:22 AM, S Ellison <S.Ellison at lgc.co.uk> 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. > > > > ******************************************************************* > This email and any attachments are confidential. Any use...{{dropped:8}} > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
Mike Prager
2008-Jun-03 18:35 UTC
[Rd] savePlot() no longer automatically adds an extension to the filename.
"S Ellison" <S.Ellison at lgc.co.uk> 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...Just for the record. . . This change broke a *lot* of my code, including code used by others. Windows depends on file extensions. Fortunately, fixes using getRversion are not too difficult. -- Mike Prager, NOAA, Beaufort, NC * Opinions expressed are personal and not represented otherwise. * Any use of tradenames does not constitute a NOAA endorsement.
Duncan Murdoch
2008-Jun-03 19:08 UTC
[Rd] savePlot() no longer automatically adds an extension to the filename.
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
S Ellison
2008-Jun-04 11:44 UTC
[Rd] savePlot() no longer automatically adds an extension to the filename.
>>> Michael Prager <Mike.Prager at noaa.gov> 06/04/08 4:28 AM >>> >There is much to be said for consistency (across platforms and >functions) and stability (across versions) in software.I could not agree more. But while consistency is an excellent reason for making the patch consistent across platforms, it doesn't help decide what the consistent behaviour should be. It is as strong an argument for retaining the original behaviour at 2.6.x as for keeping a change. As to filename extensions or their lack; in practice, RGui.exe addds a defult Rdata extension on saving a workspace via the GUI, and so does saving history, so we already have overwriteable default extensions for those purposes even though the command line behaviour doesn't do that. And it genuinely does help, which is my main motivation here. The main advantage of the present patch is that it delivers _most_ of the optional behaviours missing from both 2.6.2 and 2.7.0 without adding an extra parameter. But it isn't the best that could be done. If there is a platform-independent way of keeping the default extension-by-type and allowing the option of removing it entirely (in other words, an extra parameter to savePlot) I'd personally see that as a better way forward than the present patch. An alternative might be to keep the 2.7.0 savePlot and define a new convenience function (SavePlot, say, or save.plot for extra dottiness) which provides the wrapper. It would have impact on legacy code, but it is a lot easier to change a function name throughout legacy code than to change supplied parameters. In the mean time, consistency arguments would indicate that the present patch should be applied to all platforms if at all. Steve E ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}
S Ellison
2008-Jun-04 11:57 UTC
[Rd] savePlot() no longer automatically adds an extension to the filename.
Apologies; in my last post (below) I should have distinguished between action on the current patch and suggested action for the future. I bow to Duncan on the fate of the current patch, as he's managing it. The suggestions of an extra savePlot parameter or a wrapper function with extension default were suggestions for possible future tidying-up in subsequent releases. Steve E>>> "S Ellison" <S.Ellison at lgc.co.uk> 06/04/08 12:44 PM >>> >>> Michael Prager <Mike.Prager at noaa.gov> 06/04/08 4:28 AM >>> >There is much to be said for consistency (across platforms and >functions) and stability (across versions) in software.I could not agree more. But while consistency is an excellent reason for making the patch consistent across platforms, it doesn't help decide what the consistent behaviour should be. It is as strong an argument for retaining the original behaviour at 2.6.x as for keeping a change. As to filename extensions or their lack; in practice, RGui.exe addds a defult Rdata extension on saving a workspace via the GUI, and so does saving history, so we already have overwriteable default extensions for those purposes even though the command line behaviour doesn't do that. And it genuinely does help, which is my main motivation here. The main advantage of the present patch is that it delivers _most_ of the optional behaviours missing from both 2.6.2 and 2.7.0 without adding an extra parameter. But it isn't the best that could be done. If there is a platform-independent way of keeping the default extension-by-type and allowing the option of removing it entirely (in other words, an extra parameter to savePlot) I'd personally see that as a better way forward than the present patch. An alternative might be to keep the 2.7.0 savePlot and define a new convenience function (SavePlot, say, or save.plot for extra dottiness) which provides the wrapper. It would have impact on legacy code, but it is a lot easier to change a function name throughout legacy code than to change supplied parameters. In the mean time, consistency arguments would indicate that the present patch should be applied to all platforms if at all. Steve E ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:16}}