简体   繁体   English

S3通用方法没有出现在包装手册中

[英]S3 generic method not appearing in package manual

In my R package, a few functions are omitted from the package manual .pdf file - and they are all S3 methods where several functions are documented together. 在我的R包中,包手册.pdf文件中省略了一些函数 - 它们都是S3方法,其中一起记录了几个函数。 All other "normal" functions appear correctly, so I suspect I'm not documenting the S3 methods correctly. 所有其他“正常”功能正确显示,所以我怀疑我没有正确记录S3方法。

I want an entry for myfun to appear in the manual. 我希望myfun一个条目出现在手册中。 Right now, the function is missing from the .pdf manual entirely, though it can still be called correctly and its help page referenced with ?myfun . 现在,完全没有.pdf手册中的功能,虽然它仍然可以正确调用,其帮助页面用?myfun引用。 Are my Roxygen2 keywords wrong? 我的Roxygen2关键字错了吗?

#' @export
myfun <- function(...) UseMethod("myfun")

#' @inheritParams myfun
#' @describeIn myfun Create a frequency table from a vector.
#' @export
#' @keywords internal

myfun.default <- function(vec, sort = FALSE, show_na = TRUE, ...) {
...
}

#' @inheritParams myfun.default
#' @describeIn myfun Create a frequency table from a data.frame,
#' supplying the unquoted name of the column to tabulate.
#' @export
#' @keywords internal
tabyl.data.frame <- function(.data, ...){
...
}

(I omitted the @title, @description, @param, @return, @examples lines to keep this question shorter but can edit them in if relevant). (我省略了@title, @description, @param, @return, @examples行来缩短这个问题,但如果相关则可以编辑它们)。

The generic methods are exporting as intended, so that the user only sees myfun() and not myfun.default() or myfun.data.frame() , unless they use the triple colon ::: . 泛型方法按预期导出,因此用户只能看到myfun()而不是myfun.default()myfun.data.frame() ,除非他们使用三重冒号::: I'd like to retain that behavior, so the user just calls myfun , while also having an entry for myfun in the package manual. 我想保留这种行为,因此用户只需调用myfun ,同时在包手册中也有myfun的条目。

I removed @keywords internal in the two myfun. 我在两个myfun.删除了@keywords internal myfun. methods and that did it: myfun appears in the package's manual. 方法和它做了: myfun出现在包的手册中。 I also switched to @rdname myfun instead of @describeIn myfun , to eliminate the section "Methods (by class):" in the function's documentation. 我也切换到@rdname myfun而不是@describeIn myfun ,以消除函数文档中的“Methods(by class):”部分

What made this hard to isolate was that if I run devtools::document() and then don't restart the session, the methods myfun.data.frame and myfun.default are visible in RStudio's autocomplete and can be called directly. 让这很难分离的是,如果我运行devtools::document()然后不重启会话,方法myfun.data.framemyfun.default在RStudio的自动完成中可见,并且可以直接调用。 They are not supposed to be accessible to the user, and I thought my Roxygen2 documentation was to blame. 它们不应该被用户访问,我认为我的Roxygen2文档应该受到指责。

In fact, all I had to do was remove @keywords internal . 事实上,我所要做的就是删除@keywords internal

The methods myfun.data.frame and myfun.default do appear in the autocomplete after typing ? 该方法myfun.data.framemyfun.default 打字后出现在自动完成? , eg, ?myfun.default , but I think there's no way around that (and it directs to the single help page for all three myfun functions, anyway). ,例如, ?myfun.default ,但我认为没有办法解决这个问题(无论如何,它指向所有三个myfun函数的单一帮助页面)。 This is standard. 这是标准的。 For example, ?print.aov is a visible help file while print.aov() cannot be called directly. 例如, ?print.aov是一个可见的帮助文件,而print.aov()不能直接调用。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM