From 4ef6ec3173e74a81910d9e541181d696f108b4db Mon Sep 17 00:00:00 2001 From: smeyer Date: Wed, 8 May 2024 21:51:50 +0000 Subject: [PATCH] tweak citation() with newline-separated URLs git-svn-id: https://svn.r-project.org/R/trunk@86528 00db46b3-68df-0310-9c12-caf00c1e9a41 --- src/library/utils/R/citation.R | 8 +++++--- tests/reg-tests-3.R | 9 ++++++++- tests/reg-tests-3.Rout.save | 25 +++++++++++++++++++------ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/library/utils/R/citation.R b/src/library/utils/R/citation.R index c879ab27435..8d25385c84e 100644 --- a/src/library/utils/R/citation.R +++ b/src/library/utils/R/citation.R @@ -1439,13 +1439,15 @@ function(package = "base", lib.loc = NULL, auto = NULL) } if(!length(z$url) && !is.null(url <- meta$URL)) { + ## WRE: "a list of URLs separated by commas or whitespace". ## Cannot have several URLs in BibTeX and bibentry object URL ## fields (PR #16240). - if(grepl("[, ]", url)) { + if(length(urls <- strsplit(url, "[, \n]+")[[1L]]) > 1L) { ## Show the first URL as the BibTeX url, and add the others ## to the note (PR#18547). - z$url <- sub(",.*", "", url) - z$note <- paste0(z$note, sub("^[^,]*, ?", ", ", url)) + z$url <- urls[1L] + z$note <- paste0(c(z$note, sprintf("\\url{%s}", urls[-1L])), + collapse = ", ") } else z$url <- url } diff --git a/tests/reg-tests-3.R b/tests/reg-tests-3.R index 09bde772707..f6736a636ae 100644 --- a/tests/reg-tests-3.R +++ b/tests/reg-tests-3.R @@ -253,7 +253,7 @@ stopifnot(exprs = { pkg <- "nlme" (hasME <- requireNamespace(pkg, quietly=TRUE, lib.loc = .Library)) if(hasME) withAutoprint({ - c2 <- citation(package=pkg) + c2 <- citation(pkg, .Library) ## avoid spurious diffs: c2$author[[1]]$given[[1]] <- "J." c2$year[[1]] <- "9999" @@ -277,6 +277,13 @@ if(hasME) withAutoprint({ nchar(f2N[ie]) < nchar(f2B[ie]) startsWith(f2B[ie], f2N[ie]) }) + + desc <- packageDescription(pkg, .Library) + desc$URL <- paste(URL1 <- "https://example.org", + "https://example.com", sep = "\n") # via continuation line + desc$Repository <- NULL + c3 <- citation(auto = desc) + stopifnot(identical(print(c3$url), URL1)) # R <= 4.4.0 gave both URLs }) cat('Time elapsed: ', proc.time(),'\n') diff --git a/tests/reg-tests-3.Rout.save b/tests/reg-tests-3.Rout.save index ff6e18b734a..2aef01593c4 100644 --- a/tests/reg-tests-3.Rout.save +++ b/tests/reg-tests-3.Rout.save @@ -1,5 +1,5 @@ -R Under development (unstable) (2024-02-15 r85920) -- "Unsuffered Consequences" +R Under development (unstable) (2024-05-07 r86527) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu @@ -927,8 +927,8 @@ standardGeneric for "chol2inv" defined from package "base" function (x, ...) standardGeneric("chol2inv") - - + + Methods may be defined for arguments: x Use showMethods(chol2inv) for currently available ones. > @@ -969,7 +969,7 @@ packages. > (hasME <- requireNamespace(pkg, quietly=TRUE, lib.loc = .Library)) [1] TRUE > if(hasME) withAutoprint({ -+ c2 <- citation(package=pkg) ++ c2 <- citation(pkg, .Library) + ## avoid spurious diffs: + c2$author[[1]]$given[[1]] <- "J." + c2$year[[1]] <- "9999" @@ -993,8 +993,15 @@ packages. + nchar(f2N[ie]) < nchar(f2B[ie]) + startsWith(f2B[ie], f2N[ie]) + }) ++ ++ desc <- packageDescription(pkg, .Library) ++ desc$URL <- paste(URL1 <- "https://example.org", ++ "https://example.com", sep = "\n") # via continuation line ++ desc$Repository <- NULL ++ c3 <- citation(auto = desc) ++ stopifnot(identical(print(c3$url), URL1)) # R <= 4.4.0 gave both URLs + }) -> c2 <- citation(package = pkg) +> c2 <- citation(pkg, .Library) > c2$author[[1]]$given[[1]] <- "J." > c2$year[[1]] <- "9999" > c2$note[[1]] <- sub("3.1-[0-9]*$", "3.1-999", c2$note[[1]]) @@ -1066,7 +1073,13 @@ A BibTeX entry for LaTeX users is + startsWith(f2B[ie], f2N[ie]) + }) [1] 4 +> desc <- packageDescription(pkg, .Library) +> desc$URL <- paste(URL1 <- "https://example.org", "https://example.com", sep = "\n") +> desc$Repository <- NULL +> c3 <- citation(auto = desc) +> stopifnot(identical(print(c3$url), URL1)) +[1] "https://example.org" > > cat('Time elapsed: ', proc.time(),'\n') -Time elapsed: 2.245 0.124 2.369 0.001 0 +Time elapsed: 2.884 0.14 3.09 0.003 0 >