Hi, I have a tiny question about the graphics change in R 2.7.0. If I write a script ? la: options(device="pdf") formals(pdf)[c("file","onefile","width","height")] <- list("~/Rplot %03d.pdf", FALSE, 8, 8) plot(3) plot(4) both plots will be written into ONE pdf file. (not two as expected) This worked fine under 2.6.x In R 2.7.0 I have to write: options(device="pdf") formals(pdf)[c("file","onefile","width","height")] <- list("~/Rplot %03d.pdf", FALSE, 8, 8) pdf.options(onefile=F) plot(3) plot(4) In the NEWS doc for R 2.7.0 is written: pdf() now takes defaults from the new function pdf.options() ... Fine. But is there no way to use formals in that context (or more precisely to preset 'onefile' because other arguments are taken from formals)? I have several scripts written for R 2.6 and that would mean that I have to rewrite all of them. R version 2.7.0 (2008-04-22) powerpc-apple-darwin8.10.1 locale: en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base Many thanks in advance, --Hans
On Mon, 26 May 2008, Hans-Joerg Bibiko wrote:> Hi, > > I have a tiny question about the graphics change in R 2.7.0. > > If I write a script ? la: > > options(device="pdf") > formals(pdf)[c("file","onefile","width","height")] <- list("~/Rplot%03d.pdf", > FALSE, 8, 8) > plot(3) > plot(4) > > both plots will be written into ONE pdf file. (not two as expected) > This worked fine under 2.6.x > > In R 2.7.0 I have to write: > > options(device="pdf") > formals(pdf)[c("file","onefile","width","height")] <- list("~/Rplot%03d.pdf", > FALSE, 8, 8) > pdf.options(onefile=F) > plot(3) > plot(4) > > In the NEWS doc for R 2.7.0 is written: > pdf() now takes defaults from the new function pdf.options() ... > > Fine. But is there no way to use formals in that context (or more precisely > to preset 'onefile' because other arguments are taken from formals)?No. Any defaults you add to a local modification of pdf() are ignored. If you want to make such a modification you also need to alter the body of the function.> I have several scripts written for R 2.6 and that would mean that I have to > rewrite all of them.That's what happens when you make alterations to R's own functions -- you have to track the changes to R. I really don't see why you don't just call pdf("~/Rplot%03d.pdf", width=8, height=8, onefile = FALSE) which is what I see many other people doing. After all, if you do open multiple pdf() devices in the script they will write on the same files ....> > R version 2.7.0 (2008-04-22) > powerpc-apple-darwin8.10.1 > > locale: > en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > > Many thanks in advance, > > --Hans > ______________________________________________ > 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.-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Hans-Joerg Bibiko wrote:> Hi, > > I have a tiny question about the graphics change in R 2.7.0. > > If I write a script ? la: > > options(device="pdf") > formals(pdf)[c("file","onefile","width","height")] <- list("~/Rplot > %03d.pdf", FALSE, 8, 8) > plot(3) > plot(4) > > both plots will be written into ONE pdf file. (not two as expected) > This worked fine under 2.6.x > > In R 2.7.0 I have to write: > > options(device="pdf") > formals(pdf)[c("file","onefile","width","height")] <- list("~/Rplot > %03d.pdf", FALSE, 8, 8) > pdf.options(onefile=F) > plot(3) > plot(4) > > In the NEWS doc for R 2.7.0 is written: > pdf() now takes defaults from the new function pdf.options() ... > > Fine. But is there no way to use formals in that context (or more > precisely to preset 'onefile' because other arguments are taken from > formals)? >As Brian said, no. But if you hadn't tried to be so clever, you wouldn't have this problem. You can write a new function that calls pdf(), and give it whatever defaults you like. For example, pdf <- function(file="foo", onefile=FALSE, width=8, height=8,...) grDevices::pdf(file=file, onefile=onefile, width=width, height=height, ...) As far as the original device function is concerned, file, onefile, width and height will never be missing, so the original default values will never be used. And because this approach doesn't modify the implementation of a base function, it should be more robust to changes there: we're fairly unlikely to change the interpretation of any of those 4 parameters, and would not do so without NEWS notice in advance. Duncan Murdoch> I have several scripts written for R 2.6 and that would mean that I > have to rewrite all of them. > > R version 2.7.0 (2008-04-22) > powerpc-apple-darwin8.10.1 > > locale: > en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > > Many thanks in advance, > > --Hans > ______________________________________________ > 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. >