Re: [R] Existence of formal arguments.

From: Rolf Turner <r.turner_at_auckland.ac.nz>
Date: Fri, 06 Jun 2008 13:53:34 +1200

On 6/06/2008, at 12:57 PM, Erik Iverson wrote:

> Note the difference between
>
> test <- function(a) {
> exists("a", mode = "symbol")
> }
> test()
>
> and
>
> test2 <- function(a) {
> exists("a", mode = "numeric") #say
> }
> test2()
>
> and then note that the default mode argument to exists is "any".

Basically, I think, you're saying that a formal argument exists ``as a symbol''
(even if the object named doesn't exist) and that's why exists("a") returns TRUE
in these circumstances.

I'm still a bit puzzled, but:

Although test() gives TRUE and test2() gives FALSE, both test(a) and test2(a) throw an error:

Error in exists("a", mode = "symbol") : object "a" not found

and

Error in exists("a", mode = "numeric") : object "a" not found

whereas if I don't say anything about the mode, as in

test3 <- function(a) {

   exists("a")
}

then test3(a) evaluates to TRUE (even though there is no ``a'' anywhere in
the search path.

Also with a redundant specification of the mode, as in

test4 <- function(a){

   exists("a",mode="any")
}

one gets test4(a) to be TRUE (no error thrown).

I don't see the pattern. But it's probably not worth wasting time on.

                cheers,

                        Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

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. Received on Fri 06 Jun 2008 - 03:07:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 06 Jun 2008 - 03:30:38 GMT.

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

list of date sections of archive