Skip to content

Commit

Permalink
tweak citation() with newline-separated URLs
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@86528 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
smeyer committed May 8, 2024
1 parent 9711c6f commit 4ef6ec3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/library/utils/R/citation.R
Expand Up @@ -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
}
Expand Down
9 changes: 8 additions & 1 deletion tests/reg-tests-3.R
Expand Up @@ -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"
Expand All @@ -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')
25 changes: 19 additions & 6 deletions 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

Expand Down Expand Up @@ -927,8 +927,8 @@ standardGeneric for "chol2inv" defined from package "base"

function (x, ...)
standardGeneric("chol2inv")
<bytecode: 0x5582a67fbc00>
<environment: 0x5582a67f7608>
<bytecode: 0x55b47a1434b0>
<environment: 0x55b47a13b088>
Methods may be defined for arguments: x
Use showMethods(chol2inv) for currently available ones.
>
Expand Down Expand Up @@ -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"
Expand All @@ -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]])
Expand Down Expand Up @@ -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
>

0 comments on commit 4ef6ec3

Please sign in to comment.