dar*_*sco 48 documentation r package roxygen roxygen2
简短版本:我可以使用Normal包装模拟文件吗?statsroxygen
长版本:我正在开发一个软件包,并试图通过在一个标题下收集一些具有公共输入/参数的函数来使文档更具可读性,这将是对该组的通用引用.每个功能仍应独立地供最终用户使用.
我把文档作为灵感Normal,给出了许多与正态分布相关的方法,例如stats::dnorm().
当我搜索时,?dnorm我发现帮助部分的名称Normal即使Normal看起来不是导出的函数或对象.
我试过的是将以下内容放入funs.R:
##' @rdname funs
##' @name funs
##' @aliases sum1
##' @aliases prod1
##' @title Two functions
##' @param x X
##' @param y Y
##' @return sum1 returns x+y
##' \cr
##' prod1 returns x*y
##' @examples
##' sum1(3,4)
##' prod1(3,4)
##' @export
sum1 <- function(x,y) x+y
##' @export
##' @rdname funs
prod1 <- function(x,y) x*y
Run Code Online (Sandbox Code Playgroud)
然后我继续roxygen2上面的运行.困难在于,当R CMD check在这个最小的包上运行时,它发现无法加载包undefined exports: funs.如果我删除##' @name funs包通过的行,R CMD check但帮助部分的名称sum1不是funs.如果我在示例部分下面添加以下内容:
##' @export
funs <- function(x) x
Run Code Online (Sandbox Code Playgroud)
它通过,我可以看到我希望格式化的帮助,但我导出一个无意义的功能,以使名称正确显示.
我尝试查看源帮助文件stats以查看它是如何实现的,但它们的.Rdx格式我不知道如何显示.
此外,在一个相关的说明,做这种事情什么是 Normal?
require(stats)
getAnywhere("Normal")
> no object named 'Normal' was found
Run Code Online (Sandbox Code Playgroud)
更新:
@TylerRinker - 我担心这是我尝试过的第一件事.这将函数组合到一个.Rd文件中,但相关帮助的名称与第一个函数的名称相同,这是我试图避免的:
##' sum
##' gives the sum
##' @param x X
##' @param y Y
##' @return sum1 returns x+y
##' @examples
##' sum1(3,4)
##' @rdname funs
##' @export
sum1 <- function(x,y) x+y
##' product
##' gives the product
##' @return prod1 returns x*y
##' @examples
##' prod1(3,4)
##' @rdname funs
##' @export
prod1 <- function(x,y) x*y
Run Code Online (Sandbox Code Playgroud)
@Andrie - 这个解决方案导致完全相同的难度,帮助的名称与第一个功能相同.
也许这是不可能的......
Cal*_*imo 21
据我所知,在.Rd文件中记录3个名称的唯一方法是记录3个实际对象.但诀窍是:其中一个可以NULL导出而不导出!
##' @name funs
##' @rdname funs
##'
##' @title Two functions of sum1 and prod1
##'
##' @param x =X
##' @param y =Y
##'
##' @return x*y (prod1) or x+y (sum1).
NULL
##' @rdname funs
##' @examples
##' sum1(3,4)
##' @export
sum1 <- function(x,y) x+y
##' @rdname funs
##' @examples
##' prod1(3,4)
##' @export
prod1 <- function(x,y) x*y
Run Code Online (Sandbox Code Playgroud)
它看起来很hacky,但它的工作原理.
dar*_*sco 20
这是我发现的最好的解决方法,但是如果有更好的东西出现,我很乐意改变已接受的答案......
##' @name funs
##' @aliases sum1
##' @aliases prod1
##'
##' @title Two functions of x and y
##'
##' @param x =X
##' @param y =Y
##'
##' @note \code{funs} is a generic name for the functions documented.
##' \cr
##' If called, \code{funs} returns its own arguments.
##'
##' @rdname funs
##' @export
funs <- function(x,y) {identity(c(x,y))}
##'
##' @rdname funs
##' @return \code{sum1(x,y)} returns x+y
##' @examples
##' sum1(3,4)
##' @export
sum1 <- function(x,y) x+y
##'
##' @rdname funs
##' @return \code{prod1(x,y)} returns x*y
##' @examples
##' prod1(3,4)
##' @export
prod1 <- function(x,y) x*y
Run Code Online (Sandbox Code Playgroud)
请注意,格式化避免了使用,@usage以避免使其成为可报告的错误.
我可以看到如何在github上更好地解决这个问题.
使用的更好的解决方案@usage是添加以下行:
##' @usage funs(x,y) A nominal function of x and y
Run Code Online (Sandbox Code Playgroud)
第一次使用后
##' @rdname funs
##' @export
Run Code Online (Sandbox Code Playgroud)
但是我正在努力减少号码.R CMD check为了安抚权力而引发的警告,特别是以下内容:
Functions with \usage entries need to have the appropriate \alias
entries, and all their arguments documented.
The \usage entries must correspond to syntactically valid R code.
Run Code Online (Sandbox Code Playgroud)
这最后可能是我阅读文档的错误@usage.
非常感谢.
| 归档时间: |
|
| 查看次数: |
7928 次 |
| 最近记录: |