Learn R Programming

DOIcreator (version 0.1.0)

add_doi: Add DOIs to References in a Word Document

Description

This function reads a 'Word' document containing bibliographic references, fetches their corresponding DOIs via the 'CrossRef' API, and writes a new 'Word' document with the DOIs appended to each reference.

Usage

add_doi(input_path, output_path, reference_lines = 50)

Value

Character vector of references with appended DOIs. References that could not be matched return "NA".

Arguments

input_path

Character. Path to the input 'Word' document (.docx) containing references. Can be absolute (e.g., "C:/Users/.../references.docx") or relative (e.g., "./references.docx").

output_path

Character. Path where the output 'Word' document with DOIs will be saved. If the file exists, it will be overwritten.

reference_lines

Numeric. Number of lines from the end of the document to treat as references. Default is 50. Only lines with more than 30 characters are processed.

Examples

Run this code
# \donttest{
# Basic usage: fetch DOIs for last 50 lines in a 'Word' document
add_doi(
  input_path  = "E:/references.docx",
  output_path = "E:/references_doi.docx",
  reference_lines = 50
)

# Notes:
# - input_path must exist and contain references.
# - output_path will be overwritten if it exists.
# - Some references may return DOI "NA" if not found on 'CrossRef'.
# }

Run the code above in your browser using DataLab