[R] Existence of formal arguments.

Erik Iverson iverson at biostat.wisc.edu
Fri Jun 6 02:57:53 CEST 2008


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".

Rolf Turner wrote:
> 
> I just discovered what seems to me to be a slight funny in respect
> of formal argument names.  If I define a function
> 
>     foo <- function(a,b){ ... whatever ...}
> 
> then ``inside'' foo() the exists() function will return TRUE
> from ``exists("a") whether an object named ``a'' exists or not.
> But get("a") will yield an error ``object "a" not found''
> in these circumstances.
> 
> I presume there is a reason for specifying that an object named
> by a formal argument always exists --- but it is mysterious by my
> standards.  Can anyone explain the reason for this behaviour?
> 
> This is just idle curiosity --- or my hunger for knowledge, whichever
> way you want to look at it :-) --- it doesn't really matter.
> 
>     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.



More information about the R-help mailing list