Citing articles using roxygen2

前端 未结 2 808
花落未央
花落未央 2021-01-03 23:36

As in this question, I would like to include citations to articles in function documentation. I use roxygen2 for all documentation, and it appears that there wa

2条回答
  •  天涯浪人
    2021-01-04 00:20

    The Rdpack package promises to deliver the functionality that you requested.

    To get set up, you also need to add the line RdMacros: Rdpack to your package's DESCRIPTION file (note the capital M), and add Rdpack to the Imports: field.

    Then you can save your bibtex library in to inst/REFERENCES.bib, and cite them in your documentation with:

    #' @references{
    #'   \insertRef{bibtexKey}{YourPackageName}
    #' }
    #'
    #' # The below line ought to be included in at least one of your documentation
    #' # sections, so that roxygen2 adds Rdpack to your NAMESPACE file.
    #'
    #' @importFrom Rdpack reprompt
    

    I initially encountered some errors when first using the package; re-starting R seemed to do the trick.

    Warnings about unknown macro '\insertRef' will be encountered if building documentation with devtools::document(), as devtools does not read the 'RdMacros' line of the DESCRIPTION file; they can be safely ignored. The references may not be rendered correctly by devtools, but will be when the package is finally built; to view them in their proper formatting in the interim you can run R CMD Rd2pdf from a separate command window.

提交回复
热议问题