RcppCore / RcppEigen

Rcpp integration for the Eigen templated linear algebra library
Other
111 stars 40 forks source link

fastLm() argument name clash with apply() #87

Closed EddieYang211 closed 4 years ago

EddieYang211 commented 4 years ago

Hi,

I was trying to residualize many columns in a matrix using apply() and RcppEigen::fastLm() but it seems that both functions take an argument "X", causing error.

Here is an example:

// residualize columns 3,4 against columns 1,2
a <- matrix(1:8, 2, 4)
apply(a[,3:4], 2, RcppEigen::fastLm, X=a[,1:2])

Running the above lines generate the following error:

Error in match.fun(FUN) : '2' is not a function, character or symbol

Is there a way around this or would it be possible to change the argument names of fastLm()?

Thanks!

eddelbuettel commented 4 years ago

Of course there is; define a proper local function, or use e.g. mapply to apply with multiple args.

Is that really the error you got? Expecting a function in position two makes me think you ran sapply or lapply, not apply. I am closing this at it has nothing to with RcppEigen.