[英]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.我在自己的包中使用了 mgcv 包,到目前为止一切运行良好。 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.但是,我尝试将 Tweedie 系列对象(“Tweedie()”、“tw()”)引入到我的包中,但是在尝试使用后者时出现错误。
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我在 NAMESPACE 文件中有这个
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 加载我的包:
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()?所以我想知道我在这里做错了什么,或者我怎样才能通过安装而不使用 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.不确定这是否是最优雅的解决方案,但在此处的帮助下R 包 - 从导入的包中传输环境解决方案是从 mgcv 重新导出 ldTweedie 函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.