14

我正在学习使用氧气。我看到rd vignette提倡使用“_PACKAGE”来表示我正在创建包文档,并说“如果已经有一个名为 pkgname() 的函数,这也有效。”

我还看到了R packages book的使用方法

NULL

指定了@docType 和@name,但是当我尝试使用任何一种方法制作玩具示例时,它都无法按我的预期工作。

作为一个玩具示例,我想制作一个包含“hello()”函数的“hello”包。

我希望获得有关我的 hello的文档

?hello

或者类似的东西

package?hello

我希望获得有关包含的 hello函数的文档

?hello()

我哪里错了?- 使用 roxygen 实现,我尝试查询文档的方式,不正确的期望,还是其他什么?

我已经查看了有关包文档功能文档的问题,但我还不清楚。

以下是有关我的玩具示例的一些详细信息:

你好/描述文件:

Package: hello
Type: Package
Title: A mostly empty package
Version: 0.1
Date: 2016-06-21
Authors@R: person("Some", "Person", email = "fake@madeup.org", role = c("aut", "cre"))
Description: More about what it does (maybe more than one line)
License: MIT
LazyData: TRUE
RoxygenNote: 5.0.1.9000

你好/R/你好.R

#' hello
#'
#' This is a mostly empty package to learn roxygen documentation.
#'
#' Hello allows me to learn how to write documentation in comment blocks
#' co-located with code.
#' @docType package
#' @name hello
"_PACKAGE"

#' hello
#'
#' This function returns "Hello, world!".
#' @export
#' @examples
#' hello()

hello <- function() {
  print("Hello, world!")
}

这样,在我运行之后document(),就会生成 hello/man/hello.Rd。它包含我为 hello 包和 hello() 函数编写的描述的组合。?hello并且?hello()都返回那个 .Rd 文件。

这是 .Rd 的样子:

% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/hello.R
\docType{package}
\name{hello}
\alias{hello}
\alias{hello-package}
\title{hello}
\usage{
hello()
}
\description{
This is a mostly empty package to learn roxygen documentation.

This function returns "Hello, world!".
}
\details{
Hello allows me to learn how to write documentation in comment blocks
co-located with code.
}
\examples{
hello()
}
4

3 回答 3

9

通过@hadley,“不要使用@name hello。这会覆盖默认命名”和“有时您需要重新启动R,因为devtools和dev docs有问题”

因此,如果我将 hello.R 文件更改为:

#' hello
#'
#' This is a mostly empty package to learn roxygen documentation.
#'
#' Hello allows me to learn how to write documentation in comment blocks
#' co-located with code.
"_PACKAGE"

#' hello
#'
#' This function returns "Hello, world!".
#' @export
#' @examples
#' hello()

hello <- function() {
  print("Hello, world!")
}

然后document()制作 hello-package.Rd 和 hello.Rd 文件。在我加载之后library(hello),然后package?hello提供包文档,并?hello提供函数文档,正如我所追求的!

再次感谢您,@hadley!

于 2016-06-21T19:46:39.170 回答
0

正如 Johan Larsson 和 brendan 在对此答案的评论中指出的那样,该函数的别名似乎被包覆盖了。

这里这里提到了一个解决方案。它是添加@aliases {pkgname}-package(在这种情况下@aliases hello-package)。

于 2021-02-05T07:04:26.200 回答
0

我看到它反复说需要添加@aliases {pkgname}-package,但我不清楚是在 hello 函数注释块中还是在 package doc 块中。

剧透警报:它位于包文档块中:

#' hello
#'
#' This is a mostly empty package to learn roxygen documentation.
#'
#' Hello allows me to learn how to write documentation in comment blocks
#' co-located with code.
#' @aliases hello-package
"_PACKAGE"

#' hello
#'
#' This function returns "Hello, world!".
#' @export
#' @examples
#' hello()

hello <- function() {
  print("Hello, world!")
}
于 2021-07-17T17:50:55.587 回答