[R] Evaluation of function names...
gunter.berton at gene.com
Fri Jun 7 16:14:09 CEST 2013
Thank you. That answers my question.
On Fri, Jun 7, 2013 at 7:09 AM, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
> On 07/06/2013 14:49, Bert Gunter wrote:
>> Feel free to provide me a link or reference instead of an answer.
>> f <- function() function(x)rnorm(x)
>> g <- f()
>> ##  -0.4448492 -0.2379978 -0.4537394
>> ## But
>> rnorm <- function()1 ## nasty nasty
>> ## 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 ...
> Not if done right. The package should importFrom(stats, rnorm).
>> 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.
> 'Writing R Extensions' says
> 'The namespace controls the search strategy for variables used by functions
> in the package. If not found locally, R searches the package namespace
> first, then the imports, then the base namespace and then the normal search
> Brian D. Ripley, ripley at 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 272866 (PA)
> Oxford OX1 3TG, UK Fax: +44 1865 272595
Genentech Nonclinical Biostatistics
Internal Contact Info:
More information about the R-help