简体   繁体   English

从另一个包中调用时,无法从 mgcv 访问“ldTweedie”函数

[英]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 函数。

dplyr re-exporting %>% dplyr重新导出%>%

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从.onLoad包函数中调用的getNamespaceExports() - getNamespaceExports() called from within .onLoad package function 使用R 3.2.2从mgcv软件包运行GAM功能 - Running GAM function from mgcv package with R 3.2.2 是否有可能从另一个包中的函数@inheritParams? - Is it possible to @inheritParams from a function within another package? 如何使用R中mgcv包中的vis.gam()函数设置x和y轴的限制? - How to set limits for the x and y axis using vis.gam() function from mgcv package in r? 来自 mgcv 的 plot.gam with all.terms = TRUE 在 function - plot.gam from mgcv with all.terms = TRUE within a function 来自 mgcv 的后验覆盖 - Coverage of posterior from mgcv 当不允许使用全局变量时,从另一个 function 中访问 function 的元素(&lt;&lt;-) - Access an element of a function from within another function when not allow to use global variables(<<-) R 如何检查自定义 function 在特定 function 中是否从某个 ZEFE407A8E603AE7F14Z 调用 - R How to check that a custom function is called within a specific function from a certain package 从函数内部访问正在调用的函数 - Accessing the function that is being called from within the function 在另一个程序包或函数中装载一个程序包时,是否有可能得到通知? - Is it possible to get notified when a package is loaded within another package or function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM