我正在学习使用氧气。我看到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()
}