gpt4 book ai didi

r - 在 NAMESPACE 中使用 Roxygen 制作 S3method

转载 作者:行者123 更新时间:2023-12-01 23:45:36 24 4
gpt4 key购买 nike

我想使用 roxygen2 导出一个名为 [.myclass 的 S3method,但我看不到一种干净的方法来做到这一点。

我需要 NAMESPACE

S3method("[",myclass)

在其中或在我需要该软件包后无法使用该方法,但 roxygen2 似乎不想帮助我解决这个问题。

我可以强制它
#' @S3method [ myclass
setMethodS3("[",
c(x="myclass"),
function(x,i) {
blah blah balh
})

但是 roxygen 然后说 s3method 已弃用,我应该改用 @export,但是
#' @export
setMethodS3("[",
c(x="myclass"),
function(x,i) {
blah blah balh
})

只是不这样做。 (在 NAMESPACE 中放置一个空的导出)。

我问了包的作者,他建议我使用@method 和@export,但这也不起作用
#' @method [ myclass
#' @export
setMethodS3("[",
c(x="myclass"),
function(x,i) {
blah blah balh
})

在 NAMESPACE 中也以“export()”结尾

我错过了什么?

最佳答案

回答:

Hadley 非常有帮助,现在我意识到我不应该使用 setMethodS3 而应该使用

#' @method [ myclass
#' @export
"[.myclass" <- function(x,i) { blah blah blah }

然后一切正常。

关于r - 在 NAMESPACE 中使用 Roxygen 制作 S3method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29360132/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com