Formatting DOI in roxygen documentation

I'm preparing a package for initial submission to CRAN. (Here is the GitHub link.)

In my R CMD check, I'm getting the following Note:

Found the following URLs which should use \doi (with the DOI name only):
    File ‘get_lhy_data.Rd’:
      https://doi.org/10.1086/723805

Here is the relevant portion of my roxygen documentation for that function:

#' Get replication data from Harbridge-Yong et al. (2023)
#'
#' @description
#' `get_voteview_members()` returns replication data from:
#'
#' * Harbridge-Yong, L., Volden, C., & Wiseman, A. E. (2023).
#' The bipartisan path to effective lawmaking.
#' *The Journal of Politics*, *85*(3), 1048–1063.
#' <https://doi.org/10.1086/723805>
#'
#' or "LHY et al." for short.

How should I format the DOI number to address this Note?


I tried: replacing <https://doi.org/10.1086/723805> with \doi{10.1086/723805}, but that caused the rendered documentation to look wrong:

Description
get_voteview_members() returns replication data from:

Harbridge-Yong, L., Volden, C., & Wiseman, A. E. (2023). The bipartisan path to effective lawmaking. The Journal of Politics, 85(3), 1048–1063. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1086/723805")}

I didn't remember the syntax for this field so used GitHub · Where software is built to find an example. Noting this in case you didn't know about GitHub search. In particular you can restrict results to the "cran" user which is a mirror of CRAN packages.

Anyhow in the targets R package I see https://github.com/ropensci/targets/blob/2837739e0b752f79dd839b43b9f2edf574d579fb/R/tar_package.R#L12 gives https://github.com/ropensci/targets/blob/2837739e0b752f79dd839b43b9f2edf574d579fb/man/targets-package.Rd#L17

So you should add "doi:" in \doi{doi:10.1086/723805} I think!

Checking my .Rd file, I get the plain \doi{doi:10.1086/723805} in the source file, but when I view the rendered version in the Help pane, I still get

\Sexpr[results=rd]{tools:::Rd_expr_doi("doi:10.1086/723805")}

for that portion. Do you think this might be because I'm viewing the preview documentation? Will this be solved when the package is actually released? Seems unlikely to me; I'm just brainstorming.

Thanks for the help!

That should be fine, \doi is a built-in macro:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.