How to format DOI in Rmd vignette so that correct in Rd?

Viewed 99

When I check my package on rhub with devtools::check_rhub(), I get notes that there are incorrectly formatted DOIs in the vignettes, e.g.

URL: doi:10.1029/2002GL016612 From: inst/doc/introduction-to-sedproxy.html Message: Invalid URI scheme (use \doi for DOIs in Rd markup)

I am generating the vignettes from rmarkdown (.Rmd) files. How do I format DOIs in Rmd so that they will be correct in Rd?

2 Answers

From section 2.1.1 Documenting functions in https://cran.r-project.org/doc/manuals/r-devel/R-exts.html :

A section with references to the literature. Use \url{} or \href{}{} for web pointers, and \doi{} for DOIs (this needs R >= 3.3, see User-defined macros for more info).

Thus, it's recommended to use this for your reference as well (even if it works directly without the \doi{} by prefixing it with the https://doi.org/):

\doi{10.1029/2002GL016612}

This should not prompt a NOTE from running R CMD check with --as-cran. This seems to be the case also for vignettes / R markdown and not just Rd files.

I was struggling with this and found that using Rmarkdown to insert a link added it in this form

[Pui](https://doi.org/10.1080/02786828708959166)

This works locally anyway. I haven't tried getting it in a CRAN package yet.

Related