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
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 %>%
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With