[R] function masking and gmp questions
Duncan Murdoch
murdoch.duncan at gmail.com
Tue Jan 4 02:11:55 CET 2011
On 11-01-03 7:44 PM, Carl Witthoft wrote:
> The problem is that I can't 'insert' the :: operator inside an existing
> function. (Well, I could, but that would mean rewriting the function)
>
> I was hoping for a way to call the function, in this case turnpoints()
> in some way that told turnpoints itself to look for base::apply
You could put a copy of base::apply earlier in the search list, e.g. at
top level,
apply <- base::apply
But the pastecs package really needs a NAMESPACE defined to avoid this
kind of thing. Then it would just naturally look in base before gmp.
Since it is operating without one, this might not be the only surprise
in the way it evaluates things.
Duncan Murdoch
>
> Carl
>
>
> On 1/3/11 7:28 PM, David Winsemius wrote:
>>
>> On Jan 3, 2011, at 7:17 PM, Carl Witthoft wrote:
>>
>>> Hi,
>>> Here's the problem I ran into: the gmp package has a method for
>>> apply() so it masks the base::apply function. With gmp installed, I
>>> tried to run the function turnpoints() from the pastecs package. It
>>> fails because it calls apply() internally, like this:
>>>
>>> apply(mymatrix,1,max,na.rm=TRUE)
>>> ,
>>> but the code in the gmp package which sets up the operator overload
>>> for apply() strictly limits the arguments to the first three (a
>>> matrix, a dimension, and a function). I get, no surprise:
>>>
>>> Rgames> xs<-sin(seq(1,100)/10)
>>> Rgames> turnpoints(xs)
>>> Error in apply(ex, 1, max, na.rm = TRUE) :
>>> unused argument(s) (na.rm = TRUE)
>>>
>>> I'm assuming this is a bug in gmp code and will ask the owner of that
>>> package about it.
>>>
>>> But in the meantime, is there some way to force a function to search
>>> for functions in a different namespace, or at least to search with
>>> packages set in a different order? That is, in this example, to make
>>> turnpoints() look to package base before looking at gmp?
>>
>> In general the strategy is to use the "::" operator. Try :
>>
>> base::apply(mymatrix,1,max,na.rm=TRUE)
>>
>> (Untested in absence of example.)
>>
>>>
>>> Thanks for your help and corrections to any of my assumptions and
>>> conclusions here.
>>>
>
> ______________________________________________
> 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