From: Gabor Grothendieck <ggrothendieck_at_gmail.com>

Date: Sat 10 Jun 2006 - 06:10:35 EST

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Jun 10 06:18:00 2006

Date: Sat 10 Jun 2006 - 06:10:35 EST

x exists within the function f so the first print is TRUE; however, exists does not try to evaluate it. is.null does try to evaluate it and so at that point it discovers the error.

Perhaps you want this:

f <- function(x) if (exists(deparse(substitute(x)))) print(is.null(x))
else print("none")

if (exists("z")) rm(z)

f(z) # "none"

z <- 3

f(z) # FALSE

z <- NULL

f(z) # TRUE

On 6/9/06, Larry Howe <linux@comjet.com> wrote:

> Hello,

*>
**> I am trying to test a function argument to see if it is or is not a useful
**> number. However I cannot seem to find a test that works. For example
**>
**> > f = function(x) {
**> + print(exists("x"))
**> + print(is.null(x))
**> + }
**> >rm(x)
**> > f(z)
**> [1] TRUE
**> Error in print(is.null(x)) : Object "z" not found
**>
**> exists gives TRUE, but then any other kind of test I try to run gives me an
**> error. I need a test for existence that will work inside a function.
**>
**> Larry Howe
**>
**> ______________________________________________
**> R-help@stat.math.ethz.ch mailing list
**> https://stat.ethz.ch/mailman/listinfo/r-help
**> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
**>
*

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Jun 10 06:18:00 2006

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.1.8, at Sun 11 Jun 2006 - 05:34:59 EST.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*