Skip to content

write_bib() includes multiple URLs #2343

Closed
@bastistician

Description

The intention of #2264 was "if multiple URLs are present, drop all but the first" and that is also what is documented in help(write_bib):

the first URL listed in the ‘DESCRIPTION’ file will be used.

Unfortunately, this is not always true and may depend on the R version.
For example:

packageDescription("polyclip", fields = "URL")
#> [1] "http://www.angusj.com/delphi/clipper.php,\nhttps://sourceforge.net/projects/polyclipping,\nhttps://github.com/baddstats/polyclip"
knitr::write_bib("polyclip")

In R 4.3.0 (as intended):

@Manual{R-polyclip,
  title = {polyclip: Polygon Clipping},
  author = {Angus Johnson and Adrian Baddeley},
  year = {2023},
  note = {R package version 1.10-6},
  url = {http://www.angusj.com/delphi/clipper.php},
}

In R 4.4.0 (2nd URL in note field, 3rd URL ignored):

@Manual{R-polyclip,
  title = {polyclip: Polygon Clipping},
  author = {Angus Johnson and Adrian Baddeley},
  year = {2023},
  note = {R package version 1.10-6, 
https://sourceforge.net/projects/polyclipping},
  url = {http://www.angusj.com/delphi/clipper.php},
}

The problematic code seems to be here:

knitr/R/citation.R

Lines 96 to 99 in 726fe15

if (getRversion() < '4.3.2' && grepl('[, ]', meta$URL))
meta$URL = sub('[, ].*', '', meta$URL)
# always remove URLs after the first one
meta$URL = sub(',? .*', '', meta$URL)

I don't understand where these two replacement steps came from, but the second one is only active if it finds a space (so not for "polyclip", see above).
AFAICS, these four lines could simply be replaced by

meta$URL = sub('[, \t\n].*', '', meta$URL) 

given that the URLs can be separated by comma or whitespace.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions