Skip to contents

This function checks if the input url contains a valid Digital Object Identifier (DOI) using a regular expression. If a valid DOI is found, it extracts the DOI and optionally returns either the DOI string or the full DOI URL.

Usage

CheckDoi(url, doi.only = FALSE)

Arguments

url

A character string representing a URL or a DOI-containing text.

doi.only

Logical; if TRUE, the function returns only the DOI. If FALSE (default), the function returns the full DOI URL (i.e., "https://doi.org/" concatenated with the DOI).

Value

Returns a character string with the DOI (or full DOI URL) if found; otherwise, returns NULL.

Details

The function uses a regular expression to search for a DOI in the input. It leverages an external function GoFish (with type = FALSE) to perform additional checks. The DOI is then trimmed using a function called Trim. The regular expression pattern is designed to match the standard DOI format.

Examples

if (FALSE) { # \dontrun{
  # Example 1: Extract full DOI URL from a string containing a DOI
  doi_url <- CheckDoi("https://doi.org/10.1000/xyz123")
  # doi_url will be "https://doi.org/10.1000/xyz123"

  # Example 2: Extract only the DOI without the URL prefix
  doi_only <- CheckDoi("10.1000/xyz123", doi.only = TRUE)
  # doi_only will be "10.1000/xyz123"
} # }