Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write_bib() includes multiple URLs #2343

Closed
bastistician opened this issue May 2, 2024 · 3 comments
Closed

write_bib() includes multiple URLs #2343

bastistician opened this issue May 2, 2024 · 3 comments
Assignees
Labels
bug Bugs

Comments

@bastistician
Copy link
Contributor

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.

@yihui
Copy link
Owner

yihui commented May 23, 2024

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.

That sounds okay to me, but I'll let @dmurdoch confirm it since the two sub()s were from the PR #2264.

@yihui yihui added the bug Bugs label May 23, 2024
@dmurdoch
Copy link
Contributor

I don't remember why I had the R < 4.3.2 dependency, but if it was necessary, at least it will go away over time.

@yihui
Copy link
Owner

yihui commented May 23, 2024

Okay, then I guess we can try to use the single sub() as @bastistician suggested.

@yihui yihui closed this as completed in d499d2a May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bugs
Projects
None yet
Development

No branches or pull requests

4 participants