[R] Evaluation of function names...

Bert Gunter gunter.berton at gene.com
Fri Jun 7 15:49:10 CEST 2013


Folks:

Feel free to provide me a link or reference instead of an answer.

Preamble:

f <- function() function(x)rnorm(x)
g <- f()
g(3)
## [1] -0.4448492 -0.2379978 -0.4537394

## But
rnorm <- function()1  ## nasty nasty
g(3)
## Error in rnorm(x) : unused argument(s) (x)

## of course f <- function()function(x)stats:::rnorm(x)
## would fix this.

Question 1:
Suppose I defined f() as at top in a package namespace and exported it.
Would a user see this same error defining g() and with rnorm redefined
as above? (Assume stats is attached as usual).  I presume so, but ...

Question 2:
If the answer to Q1 is yes, (how) can this be avoided without using fully
qualified function names?

Again, a quick reference to relevant docs would suffice.

Thanks.

-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm



More information about the R-help mailing list