如何将文档添加到包(而不是包的功能)

How to add documentation to package (not to the package's functions)

我正在尝试通过 help()? 函数获取文档以显示实际包(不是它的功能,因为这是在记录包时自动完成的)。

例如,使用以下内容:

?dplyr

我们得到:

dplyr-package {dplyr}   R Documentation
dplyr: A Grammar of Data Manipulation
Description
To learn more about dplyr, start with the vignettes: browseVignettes(package = "dplyr")

Author(s)
Maintainer: Hadley Wickham hadley@rstudio.com (ORCID)

Authors:

Romain François (ORCID)

Lionel Henry

Kirill Müller (ORCID)

Other contributors:

RStudio [copyright holder, funder]

See Also
Useful links:

https://dplyr.tidyverse.org

https://github.com/tidyverse/dplyr

Report bugs at https://github.com/tidyverse/dplyr/issues

[Package dplyr version 1.0.7 Index]

我通过 Hillary Parker 的教程创建了一个基本包 catshttps://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/。我安装了它并确认它可以正常工作,例如,获取一个功能的帮助文档:

?cat_function

给出:

cat_function {cats} R Documentation
A Cat Function
Description
This function allows you to express your love of cats.

Usage
cat_function(love = TRUE)
Arguments
love    
Do you love cats? Defaults to TRUE.

Examples
cat_function()
[Package cats version 0.0.0.9000 Index]

但是,尝试获取包本身的文档:

?cats
No documentation for ‘cats’ in specified packages and libraries:
you could try ‘??cats’

从功能帮助中,我可以点击Index,然后我得到一个好的“帮助”页面,我也可以从那里点击DESCRIPTION file,但这些肯定不是就像 help(cats) 会输出的那样。

如何为我的 cats 包裹获得相同的 help() 调用?我想我一定已经阅读了所有关于创建包的教程,但只看到了一些关于添加小插图的内容,这似乎是另一回事(尽管我确实尝试添加小插图,但帮助文档仍然没有出现)。我也尝试添加一个自述文件,但结果相同。有什么窍门? =)

编辑:实际上一直在使用 usethisdevtools 来安装和 document() 但我不认为这会有什么不同,因为我没有看到这种特殊形式任何教程中记录的软件包文档。

由于您使用的是 usethis,因此您可以使用 usethis::use_package_doc()。请参阅文档 here.

您还可以阅读 Hadley's book on R packages,其中解释了这是做什么的。