Search code examples
rdevtoolsr-packageroxygen2r-usethis

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


I am trying to get documentation to show up for an actual package (not its functions, since that's done automatically when documentating the package) through the help() or ? functions.

For example, using the following:

?dplyr

We get:

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 [email protected] (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]

I created a basic package, cats, through Hillary Parker's tutorial: https://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/. I installed it and confirmed that it works correctly, e.g., getting help docs for the one function:

?cat_function

Gives:

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]

However, trying to get docs for the package itself:

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

From the function help, I can click on Index, and then I get an OK "help" page, and I can also from there click on DESCRIPTION file, but these are definitely not like what help(cats) would output.

How can I get the same help() call for my cats package? I think I must have read all tutorials about creating a package but only saw something about adding vignettes which seem to be a different thing (though I did try adding a vignette, and the help docs still didn't come up). I also tried adding a readme file, but alas, same result. What's the trick? =)

Edit: Actually been using usethis through devtools to install and document() but I don't think this would make a difference as I didn't see this particular form of package documentation documented on any of the tutorials.


Solution

  • Since you're using usethis, you can do usethis::use_package_doc(). See docs here.

    You could also read Hadley's book on R packages which explains what this is doing.