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

Add DOI badge #1440

Open
burgerga opened this issue Apr 28, 2021 · 1 comment
Open

Add DOI badge #1440

burgerga opened this issue Apr 28, 2021 · 1 comment
Labels
feature a feature request or enhancement readme 🏠 Readme, badges, ...

Comments

@burgerga
Copy link

burgerga commented Apr 28, 2021

Would be nice if we could add a DOI badge to our R packages, especially if they are published somewhere or citable using zenodo.

For example for https://zenodo.org/record/4692672 (my mdftracks package), this would be the badge:
DOI (if for some reason this won't load, please click the zenodo link, they also show the badge)

I have written a function that will add this badge:

extract_doi <- function(x) {
  # pattern from https://www.crossref.org/blog/dois-and-matching-regular-expressions/
  pattern <- ".*(10\\.\\d{4,9}/[-._;()/:A-Z0-9]+)$"
  if(!grepl(pattern, x, ignore.case = T, perl = T)) stop(glue("{x} is not a valid doi"))
  gsub(pattern, "\\1", x, ignore.case = T, perl = T)
}

use_doi_badge <- function(doi) {
  doi <- extract_doi(doi)
  src <- glue("https://zenodo.org/badge/DOI/{doi}.svg")
  href <- glue("https://doi.org/{doi}")
  use_badge("DOI", href, src)
  invisible(TRUE)
}

It accepts "naked" DOIs such as "10.5281/zenodo.4725473", or DOI links such as "https://doi.org/10.5281/zenodo.4725473"
Let me know if this would be useful, then I'll write some tests for the extract_doi function and prepare a pull request.

@jennybc
Copy link
Member

jennybc commented Sep 28, 2021

Maybe related to #1469

@jennybc jennybc added the readme 🏠 Readme, badges, ... label Sep 28, 2021
@hadley hadley added the feature a feature request or enhancement label Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement readme 🏠 Readme, badges, ...
Projects
None yet
Development

No branches or pull requests

3 participants