S3 record class for DOIs.

doi(prefix = character(), suffix = character())

is_doi(x)

is_doi_ish(x)

as_doi(x, ...)

# S3 method for biblids_doi
format(x, ..., protocol = FALSE)

# S3 method for biblids_doi
pillar_shaft(x, ...)

# S3 method for biblids_doi
knit_print(
  x,
  display = getOption("biblids.doi_display", default = "crossref"),
  inline = FALSE,
  ...
)

# S3 method for biblids_doi
is.na(x, ...)

Arguments

prefix

The naming authority.

suffix

The unique string chosen by the registrant.

x

A vector created by, or convertable to doi().

...

Additional arguments passed to the S3 method. Currently ignored, except two optional arguments options and inline; see the references below.

protocol

Logical flag, whether to prepend doi: handle protocol, as per the official DOI Handbook.

display

character scaling, giving how to display a DOI. Must be one of:

inline

Logical flag, giving whether to render DOIs as a chunk output or inline R. Usually set by knitr.

Functions

  • is_doi: Is this a biblids_doi?

  • is_doi_ish: Could this be converted to a biblids_doi using as_doi()?

  • as_doi: Normalise

Methods extending biblids_doi class (by generic):

  • format: Display a DOI

  • is.na: Detect if prefix and/or suffix is missing

Note

DOIs are returned as an S3 record class constructed by vctrs::new_rcrd(). Under the hood, these records are implemented as lists of fields (here: prefix, suffix). Support for such records may still be limited. For example, purrr::map() will erroneously loop over the fields, instead of over the DOIs (see #51). To avoid such problems, cast the DOI to a simple character vector using as.character().

See also

Examples

# this is the hard way to enter
doi(
  prefix = c("10.1038", "10.1000", "10.1007"),
  suffix = c("nphys1170", NA, "978-3-642-65840-2_5")
)
#> <digital object identifier[3]>
#> [1] 10.1038/nphys1170           <NA>                       
#> [3] 10.1007/978-3-642-65840-2_5
# DOIs are case insensitive and are compared as such
unique(as_doi(c("10.1000/foo", "10.1000/fOo")))
#> <digital object identifier[1]>
#> [1] 10.1000/foo
as_doi("10.1000/BAR") == as_doi("10.1000/bar")
#> [1] TRUE

# convert back to a (normalised) character
as.character(as_doi("10.1000/zap"))
#> [1] "10.1000/zap"

is_doi(as_doi("10.1000/1"))
#> [1] TRUE
is_doi(1L)
#> [1] FALSE
as_doi(c(
  # example DOIs are from https://www.doi.org/demos.html
  "10.1594/PANGAE.726855",
  " 10.1594/GFZ.GEOFON.gfz2009kciu ",  # leading/trailing spaces are removed
  "https://doi.org/10.1000/182",  # URL form is parsed
  "doi:10.1000/7",  # DOI from is parsed
  "foo bar",  # returns NA
  NA_character_  # returns NA
))
#> <digital object identifier[6]>
#> [1] 10.1594/PANGAE.726855          10.1594/GFZ.GEOFON.gfz2009kciu
#> [3] 10.1000/182                    10.1000/7                     
#> [5] <NA>                           <NA>                          
# \dontrun{
# there must be only one DOI per element
as_doi(c("10.1126/science.169.3946.635 10.6084/m9.figshare.97218"))
#> Error: * All elements must include one DOI only:
#>  Multiple DOIs found in one or more elements of `x`.
#>  Try extracting with `str_extract_all_doi()`.
# }
# there is extra pretty printing inside tibbles
tibble::tibble(c(doi_examples(na.rm = FALSE)[1:3]))
#> # A tibble: 3 × 1
#>   `c(doi_examples(na.rm = FALSE)[1:3])`
#>   <doi>                                
#> 1 10.1038/nphys1170                    
#> 2 NA                                   
#> 3 10.1007/978-3-642-65840-2_5          
# this can be constructed but will be NA
is.na(doi(prefix = "10.1000", suffix = NA))
#> [1] TRUE