J.C.Rougier@durham.ac.uk
2002-Jan-04 13:41 UTC
[Rd] Problem with "missing" in "local" (PR#1241)
Hi everyone, I encountered unexpected behaviour when calling "missing" within a "local" environment, namely fred <- function(x, y) { x <- as.vector(x) local({ dontwantme <- 1:100 if (missing(y)) print("No \"y\" today") }) x } whereupon I get> fred(1:10)Error in eval(expr, envir, enclos) : "missing" illegal use of missing I think it is reasonable to expect missing to work in this context (I suspect the problem relates to lazy evaluation): if not, it might be helpful to amend the help file. Cheers, Jonathan. --please do not edit the information below-- Version: platform = i686-pc-linux-gnu arch = i686 os = linux-gnu system = i686, linux-gnu status = major = 1 minor = 4.0 year = 2001 month = 12 day = 19 language = R Search Path: .GlobalEnv, Autoloads, package:base -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
ripley@stats.ox.ac.uk
2002-Jan-04 13:51 UTC
[Rd] Problem with "missing" in "local" (PR#1241)
On Fri, 4 Jan 2002 J.C.Rougier@durham.ac.uk wrote:> Hi everyone, > > I encountered unexpected behaviour when calling "missing" within a > "local" environment, namely > > fred <- function(x, y) > { > x <- as.vector(x) > local({ > dontwantme <- 1:100 > if (missing(y)) print("No \"y\" today") > }) > x > } > > whereupon I get > > > fred(1:10) > Error in eval(expr, envir, enclos) : "missing" illegal use of missing > > I think it is reasonable to expect missing to work in this context (I > suspect the problem relates to lazy evaluation): if not, it might be > helpful to amend the help file.Why do you think it reasonable? You've take a function from Evaluate an R expression in a specified environment. and evaluated it somewhere where missing() is not defined. If you had used eval() explicitly, would you think it reasonable? I doubt it. Which help file did you have in mind? -- Brian D. Ripley, ripley@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 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
J.C.Rougier@durham.ac.uk
2002-Jan-04 14:48 UTC
[Rd] Problem with "missing" in "local" (PR#1241)
Hi Brian, Prof Brian Ripley wrote:> > On Fri, 4 Jan 2002 J.C.Rougier@durham.ac.uk wrote: > > > Hi everyone, > > > > I encountered unexpected behaviour when calling "missing" within a > > "local" environment, namely > > > > fred <- function(x, y) > > { > > x <- as.vector(x) > > local({ > > dontwantme <- 1:100 > > if (missing(y)) print("No \"y\" today") > > }) > > x > > } > > > > whereupon I get > > > > > fred(1:10) > > Error in eval(expr, envir, enclos) : "missing" illegal use of missing > > > > I think it is reasonable to expect missing to work in this context (I > > suspect the problem relates to lazy evaluation): if not, it might be > > helpful to amend the help file. > > Why do you think it reasonable? You've take a function from > > Evaluate an R expression in a specified environment. > > and evaluated it somewhere where missing() is not defined. If you had > used eval() explicitly, would you think it reasonable? I doubt it.By "reasonable" in this context I mean that the operation would appear to be well-defined and useful. I can access x within the local() environment, ie it is found in the enclosing environment, and I do not think that y should be treated any differently. If I modify my function to read fred <- function(x, y) { x <- as.vector(x) local({ print(x) print(y) if (missing(y)) print("No \"y\" today") }) x } then I get the error message> fred(1:10)[1] 1 2 3 4 5 6 7 8 9 10 Error in print(y) : Argument "y" is missing, with no default This error message suggests to me that "missing(y)" would evaluate correctly.> > Which help file did you have in mind? >The help file for "missing". This points out that "missing" is not always reliable, eg after "x <- match.arg(x)". Perhaps this could be another example of "unreliability". Cheers, Jonathan. -- Jonathan Rougier Science Laboratories Department of Mathematical Sciences South Road University of Durham Durham DH1 3LE tel: +44 (0)191 374 2361, fax: +44 (0)191 374 7388 http://www.maths.dur.ac.uk/stats/people/jcr/jcr.html -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._