[R] function masking and gmp questions

David Winsemius dwinsemius at comcast.net
Tue Jan 4 01:28:28 CET 2011


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

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list