kaskr / RTMB

R bindings to TMB
Other
49 stars 6 forks source link

Error in sum(prob) : method not defined for advector argument #28

Closed darjeely closed 3 months ago

darjeely commented 4 months ago

Hi everyone!

I have used TMB package in the past which worked fine. Now I learned about the new RTMB package. Unfortunately it does not seem to work for me, it seems like the "sum" attribute is no longer available for the advector. I have (re)installed it from CRAN directly, from remotes::install_github("https://github.com/kaskr/RTMB", subdir="RTMB") as specified here, using install.packages("RTMB", repos = c("https://kaskr.r-universe.dev", "https://cloud.r-project.org")), but unfortunately when I try running tinytest::test_package("RTMB") or the example on this page or any of the examples on the RTMB page, I get the same error:

Error in sum(prob) : method not defined for advector argument (tinytest::test_package("RTMB")

or

sum(dnorm(a, mean = mua, sd = sda, log = TRUE)) : method not defined for advector argument (example here)

which I think essentially highlights the same problem.

Is there any solution to this? My R, R studio and all the packages are up to date and I tried both on a Windows and a Mac. Thank you in advance!

Kindly,

Anna

PS Edit: formatting for readability

kaskr commented 4 months ago

It's unlikely that RTMB is broken for all the combinations of installation methods / operating systems that you mention (because if that was the case, I would have received complaints from CRAN long ago...). I'm therefore guessing there could be some unfortunate conflict with another package (what is sessionInfo()?). Perhaps try the same test independent of R studio (use Rgui) ?

darjeely commented 4 months ago

Thank you so much for your quick reply. I am sorry I haven't thought of it, but there was indeed a conflict with the three loaded packages:

mvtnorm package:

Attaching package: ‘mvtnorm’

The following object is masked from ‘package:RTMB’:

    dmvnorm

and, weightedCL, after which I got the mentioned error.

The package condMVNorm causes the following error for the tinytest:

Error in dmvnorm(parms$u, Sigma = C, log = TRUE) : 
  unused argument (Sigma = C)

When I do not load these packages, the examples work fine.

kaskr commented 3 months ago

@darjeely Thanks for reporting this. The problem is in the matlab package, which defines a non-standard generic:

> matlab::sum
nonstandardGenericFunction for "sum" defined from package "matlab"

Not much I can do about that, so closing.