From 8882352ef935cc5b1891fc8f364839127ad9e055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 4 Feb 2025 14:47:04 +0100 Subject: [PATCH 1/2] feat: add support for ROR in package documentation --- DESCRIPTION | 3 ++- NEWS.md | 2 ++ R/object-package.R | 10 ++++++++++ man/roxygen2-package.Rd | 2 +- tests/testthat/_snaps/object-package.md | 13 +++++++++++++ tests/testthat/test-object-package.R | 5 +++++ 6 files changed, 33 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d37a0f02c..5f0ea2c89 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -7,7 +7,8 @@ Authors@R: c( person("Peter", "Danenberg", , "pcd@roxygen.org", role = c("aut", "cph")), person("Gábor", "Csárdi", , "csardi.gabor@gmail.com", role = "aut"), person("Manuel", "Eugster", role = c("aut", "cph")), - person("Posit Software, PBC", role = c("cph", "fnd")) + person("Posit Software, PBC", role = c("cph", "fnd"), + comment = c(ROR = "03wc8by49")) ) Description: Generate your Rd documentation, 'NAMESPACE' file, and collation field using specially formatted comments. Writing diff --git a/NEWS.md b/NEWS.md index 9f3837d78..c198e5757 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # roxygen2 (development version) +* Package documentation now converts ROR IDs into a useful link (#1698, @maelle). + * The check for unexported S3 methods was improved, so it does not hang any more if a largish data object is in the package (#1593, @jranke). diff --git a/R/object-package.R b/R/object-package.R index 9f34b70cb..3e8247e11 100644 --- a/R/object-package.R +++ b/R/object-package.R @@ -66,6 +66,16 @@ author_desc <- function(x) { } x$comment <- x$comment[!names(x$comment) %in% "ORCID"] } + if (has_name(x$comment, "ROR")) { + ror <- x$comment[["ROR"]] + + if (grepl("https?://", ror)) { + desc <- paste0(desc, " (\\href{", ror, "}{ROR})") + } else { + desc <- paste0(desc, " (\\href{https://ror.org/", ror, "}{ROR})") + } + x$comment <- x$comment[!names(x$comment) %in% "ROR"] + } if (length(x$comment) > 0) { desc <- paste0(desc, " (", x$comment, ")") diff --git a/man/roxygen2-package.Rd b/man/roxygen2-package.Rd index 574833b38..4e55cdb9e 100644 --- a/man/roxygen2-package.Rd +++ b/man/roxygen2-package.Rd @@ -31,7 +31,7 @@ Authors: Other contributors: \itemize{ - \item Posit Software, PBC [copyright holder, funder] + \item Posit Software, PBC (\href{https://ror.org/03wc8by49}{ROR}) [copyright holder, funder] } } diff --git a/tests/testthat/_snaps/object-package.md b/tests/testthat/_snaps/object-package.md index 6d8469f00..ef759ea66 100644 --- a/tests/testthat/_snaps/object-package.md +++ b/tests/testthat/_snaps/object-package.md @@ -23,6 +23,19 @@ person_desc(comment = c(ORCID = "1234", "extra")) Output [1] "H W \\email{h@w.com} (\\href{https://orcid.org/1234}{ORCID}) (extra)" + Code + # ROR comments + person_desc(comment = c(ROR = "03wc8by49")) + Output + [1] "H W \\email{h@w.com} (\\href{https://ror.org/03wc8by49}{ROR})" + Code + person_desc(comment = c(ROR = "https://ror.org/03wc8by49")) + Output + [1] "H W \\email{h@w.com} (\\href{https://ror.org/03wc8by49}{ROR})" + Code + person_desc(comment = c(ROR = "03wc8by49", "extra")) + Output + [1] "H W \\email{h@w.com} (\\href{https://ror.org/03wc8by49}{ROR}) (extra)" # useful message if Authors@R is corrupted diff --git a/tests/testthat/test-object-package.R b/tests/testthat/test-object-package.R index 72bf8bea3..885adeb1b 100644 --- a/tests/testthat/test-object-package.R +++ b/tests/testthat/test-object-package.R @@ -15,6 +15,11 @@ test_that("person turned into meaningful text", { person_desc(comment = c("ORCID" = "1234")) person_desc(comment = c("ORCID" = "https://orcid.org/1234")) person_desc(comment = c("ORCID" = "1234", "extra")) + + "ROR comments" + person_desc(comment = c("ROR" = "03wc8by49")) + person_desc(comment = c("ROR" = "https://ror.org/03wc8by49")) + person_desc(comment = c("ROR" = "03wc8by49", "extra")) }) }) From 5e3a3aefea4e6144a47fa79a5903bb2f117d7915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 4 Feb 2025 15:04:19 +0100 Subject: [PATCH 2/2] fix: adapt the code to ORCID ID checking in R devel --- tests/testthat/_snaps/object-package.md | 12 ++++++------ tests/testthat/test-object-package.R | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/testthat/_snaps/object-package.md b/tests/testthat/_snaps/object-package.md index ef759ea66..d11959f52 100644 --- a/tests/testthat/_snaps/object-package.md +++ b/tests/testthat/_snaps/object-package.md @@ -12,17 +12,17 @@ [1] "H W \\email{h@w.com} [contributor]" Code # ORCID comments - person_desc(comment = c(ORCID = "1234")) + person_desc(comment = c(ORCID = "0000-0003-4757-117X")) Output - [1] "H W \\email{h@w.com} (\\href{https://orcid.org/1234}{ORCID})" + [1] "H W \\email{h@w.com} (\\href{https://orcid.org/0000-0003-4757-117X}{ORCID})" Code - person_desc(comment = c(ORCID = "https://orcid.org/1234")) + person_desc(comment = c(ORCID = "https://orcid.org/0000-0003-4757-117X")) Output - [1] "H W \\email{h@w.com} (\\href{https://orcid.org/1234}{ORCID})" + [1] "H W \\email{h@w.com} (\\href{https://orcid.org/0000-0003-4757-117X}{ORCID})" Code - person_desc(comment = c(ORCID = "1234", "extra")) + person_desc(comment = c(ORCID = "0000-0003-4757-117X", "extra")) Output - [1] "H W \\email{h@w.com} (\\href{https://orcid.org/1234}{ORCID}) (extra)" + [1] "H W \\email{h@w.com} (\\href{https://orcid.org/0000-0003-4757-117X}{ORCID}) (extra)" Code # ROR comments person_desc(comment = c(ROR = "03wc8by49")) diff --git a/tests/testthat/test-object-package.R b/tests/testthat/test-object-package.R index 885adeb1b..c2562a5c5 100644 --- a/tests/testthat/test-object-package.R +++ b/tests/testthat/test-object-package.R @@ -12,9 +12,9 @@ test_that("person turned into meaningful text", { person_desc(role = "ctb") "ORCID comments" - person_desc(comment = c("ORCID" = "1234")) - person_desc(comment = c("ORCID" = "https://orcid.org/1234")) - person_desc(comment = c("ORCID" = "1234", "extra")) + person_desc(comment = c("ORCID" = "0000-0003-4757-117X")) + person_desc(comment = c("ORCID" = "https://orcid.org/0000-0003-4757-117X")) + person_desc(comment = c("ORCID" = "0000-0003-4757-117X", "extra")) "ROR comments" person_desc(comment = c("ROR" = "03wc8by49"))