Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No access to "ldTweedie" function from mgcv when called from within another package

I am using mgcv package within my own package and so far everything worked nicely. However, I tried to introduce Tweedie family objects ("Tweedie()", "tw()") to my package, but I am getting an error when trying to use the latter.

The function is as simple as this (simplified here):

#' @importFrom mgcv tw
#'
.FamilyLink <- function(link) {
       familyObject <- tw(link = link)
       return(familyObject)
}

and I have this in NAMESPACE file

importFrom(mgcv,tw)

So after installing the package I call my function (non-exported, it's normally used within other function from my package)

fam <- MyPackage:::.FamilyLink("log")
fam$aic(1, 1, NULL, 1, 1)
Error in ldTweedie(y, mu, p = p, phi = scale) : 
  could not find function "ldTweedie"

Then I tried adding:

importFrom(mgcv,ldTweedie)
importFrom(mgcv,tw)

Installed the package and got the same problem. However if I load my package using devtools:

devtools::load_all("MyPackage")
fam <- .FamilyLink("log")
fam$aic(1, 1, NULL, 1, 1)
[1] 4.05723

everything works fine. So I was wondering am I doing something wrong here or how can I get my package/function to work simply by installing and not having to use load_all()? Thank you

like image 618
Daniel Piacek Avatar asked Nov 07 '22 08:11

Daniel Piacek


1 Answers

Not sure if this is the most elegant solution, but with the help from here R package - Transferring environment from imported package the solution is to re-export ldTweedie function from mgcv.

dplyr re-exporting %>%

like image 65
Daniel Piacek Avatar answered Nov 12 '22 16:11

Daniel Piacek