Import BibReferences

Import Bibliography using the OpenDataBio R package

Illustrative example: import DOI values only

The Bibliographic Reference endpoint accepts a doi column and resolves the remaining metadata. This example is deliberately fictitious and has not been tested; keep the guard set to FALSE unless you replace every DOI with a real reference that you intend to register.

library(opendatabio)

cfg = odb_config(
  base_url = "http://localhost/opendatabio/api",
  token = Sys.getenv("ODB_TOKEN")
)

references = data.frame(
  doi = c(
    "10.0000/example.reference.001",
    "https://doi.org/10.0000/example.reference.002"
  )
)

SEND_REAL_DOIS = FALSE
if (SEND_REAL_DOIS) {
  job = odb_import_bibreferences(references, odb_cfg = cfg)
  odb_get_jobs(params = list(id = job$id), odb_cfg = cfg)
  odb_get_affected_ids(job_id = job$id, odb_cfg = cfg)
}

Search existing DOI values first. After processing, review reused records, warnings, and affected IDs before using reference IDs in another import.

Import a BibTeX file

#your connection
library(opendatabio)
base_url="http://localhost/opendatabio/api"
token =YOUR TOKEN HEREcfg = odb_config(base_url=base_url, token = token)
odb_test(cfg)

#read the bibliographic references in R
library(rbibutils)
bibs = readBib(file="yourFileWithReferences.bib")
formatbib <- function(x) {
  con <- textConnection("bibref", "w")
  writeBib(x,con=con)
  bibref = paste(bibref,collapse = " ")
  close(con)
  return(bibref)
}

#prepare to import to odb
bibtexts = sapply(bibs,formatbib)
data = data.frame(bibtex=bibtexts,standardize=1,stringsAsFactors = F)

#importa
jobid = odb_import_bibreferences(data,odb_cfg = cfg)
#waiting for completion
odb_get_jobs(params=list(id=jobid$id),odb_cfg = cfg)
#get the import log
dt = odb_get_affected_ids(job_id=jobid$id,odb_cfg = cfg)