Package 'c2z'

Title: A Reference Manager
Description: 'Cristin' to 'Zotero' ('c2z') aims at obtaining total dominion over 'Cristin' ('Current Research Information SysTem in Norway') and 'Zotero'. The package enables manipulating 'Zotero' libraries using 'R'. Import references from 'Cristin', 'Regjeringen', 'CRAN', 'ISBN' ('Alma', 'LoC'), and 'DOI' ('CrossRef', 'DataCite') to a 'Zotero' library. Add, edit, copy, or delete items, including attachments and collections, and export references to 'BibLaTeX' (and other formats).
Authors: Øystein Olav Skaar [aut, cre, cph]
Maintainer: Øystein Olav Skaar <[email protected]>
License: MIT + file LICENSE
Version: 0.3.0.9007
Built: 2025-03-13 15:21:02 UTC
Source: https://github.com/oeysan/c2z

Help Index


Extract DOI from a URL or String

Description

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).

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.

Value

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

Examples

## Not run: 
  # 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"

## End(Not run)

Check and Convert ISBN

Description

This function takes an input string that may contain an ISBN (or a compound string where the first component is the ISBN), cleans it by removing non-alphanumeric characters (except spaces) and spaces, and processes it with the GoFish function. If the cleaned ISBN is in the ISBN10 format, the function converts it to ISBN13. Finally, it validates the ISBN; valid ISBNs either start with "97" and are 13 characters long or start with "99" and are longer than 7 characters.

Usage

CheckIsbn(key, split.key = ",")

Arguments

key

A character string that contains an ISBN or a compound string where the first element is the ISBN.

split.key

A delimiter used to split the key. Default is ",".

Details

The function performs the following steps:

  1. Splits the input key using split.key and selects the first element.

  2. Removes foreign (non-alphanumeric) characters and spaces using nested gsub calls.

  3. Applies the GoFish function to the cleaned key (ensure that GoFish is defined in your environment).

  4. If the key is in ISBN10 format (10 characters), converts it to ISBN13 by prepending 978, recalculating the check digit, and concatenating the result.

  5. Checks that the final key is valid by confirming that it either starts with "97" (and is 13 characters long) or starts with "99" and has more than 7 characters.

Value

A cleaned and validated ISBN string. If the resulting ISBN does not meet the expected criteria, the function returns NULL.

Examples

## Not run: 
# Example with a compound string where the first part is the ISBN:
isbn_input <- "316148410X, some extra text"
valid_isbn <- CheckIsbn(isbn_input)

# Example converting an ISBN10 to ISBN13:
isbn10 <- "316148410X"
valid_isbn <- CheckIsbn(isbn10)

## End(Not run)

Search Cristin API

Description

Use search parameters for the Cristin API and return the results as a tibble. See CristinWrangler

Usage

Cristin(
  id = NULL,
  doi = NULL,
  title = NULL,
  contributor = NULL,
  issn = NULL,
  unit = NULL,
  institution = NULL,
  user = NULL,
  category = NULL,
  published_since = NULL,
  published_before = NULL,
  created_since = NULL,
  created_before = NULL,
  modified_since = NULL,
  modified_before = NULL,
  year_reported = NULL,
  project_code = NULL,
  funding_source = NULL,
  funding = NULL,
  lang = NULL,
  page = 1,
  per_page = 1000,
  max.results = NULL,
  no.results = FALSE,
  sort = NULL,
  filter = NULL,
  fields = "all",
  open.query = NULL,
  all.results = TRUE,
  force = FALSE,
  remove.duplicates = TRUE,
  base.url = "https://api.cristin.no/v2/results",
  custom.url = NULL,
  use.identifiers = TRUE,
  use.multisession = FALSE,
  min.multisession = 25,
  n.workers = NULL,
  n.chunks = NULL,
  handler = NULL,
  restore.defaults = TRUE,
  zotero = NULL,
  zotero.import = TRUE,
  zotero.check = TRUE,
  nvi = FALSE,
  remove.na = TRUE,
  replace.na = "book",
  force.type = NULL,
  silent = FALSE,
  log = list()
)

Arguments

id

The Cristin id of the result, Default: NULL

doi

DOI name (e.g. doi=10.1000/123456), Default: NULL

title

The title of the result, Default: NULL

contributor

Author's name or Cristin person id, Default: NULL

issn

The issn of the result, Default: NULL

unit

Id (e.g. unit=185.53.18.10), Default: NULL

institution

Id (one number, e.g. institution=185), name or acronym of the institution the contributors belong to, Default: NULL

user

A person's username in Cristin together with the institution id separated by colon (e.g., 'askeladd:185'), Default: NULL

category

Categories. See category codes, Default: NULL

published_since

Results published since and inclusive the given year, (yyyy), Default: NULL

published_before

Results published before and inclusive the given year, (yyyy), Default: NULL

created_since

Results created since and inclusive the given date, (yyyy-mm-dd), Default: NULL

created_before

Results created before and inclusive the given date, (yyyy-mm-dd), Default: NULL

modified_since

Results modified since and inclusive the given date, (yyyy-mm-dd), Default: NULL

modified_before

Results modified before and inclusive the given date, (yyyy-mm-dd), Default: NULL

year_reported

The year a result was reported, Default: NULL

project_code

Project code is the internal reference number used by funding source, Default: NULL

funding_source

Funding source code e.g: NFR, Default: NULL

funding

Funding source code e.g: NFR, and project_code together separated by colon (e.g., NFR:1234), Default: NULL

lang

Two letter language code, Default: NULL

page

Page number. See pagination, Default: 1

per_page

Number of items per page (1000 is max). See pagination, Default: 1000

max.results

Do you need a limit?, Default: NULL

no.results

Do you need only the number of results?, Default: FALSE

sort

Sorts on 'category' and/or 'year_published'. See search and sort. Default sort order is on 'cristin_result_id' in ascending order, Default: NULL

filter

Vector of cateogries to include in results. See category code, Default: NULL

fields

'fields = all' gives a list of result objects with all available fields. If this parameter is omitted, a list of result summaries with fewer fields will be returned, Default: all

open.query

Define your own query terms, Default: NULL

all.results

Find all results in query, Default: TRUE

force

Force is seldom wise, but sometimes..., Default: FALSE

remove.duplicates

Remove duplicates if TRUE, Default: TRUE

base.url

The base url for the Cristin API, Default: https://api.cristin.no/v2/results

custom.url

Define your own Cristin API url, Default: NULL

use.identifiers

Use if ISBN/DOI identifiers if enabled, Default: TRUE

use.multisession

Logical. If TRUE (default), parallel processing using multisession is employed; otherwise, processing is sequential.

min.multisession

Minimum number of results for using multisession. Default: 25

n.workers

Optional integer for the number of workers to be used in multisession mode. If NULL, it defaults to the number of available cores minus one (with a minimum of one).

n.chunks

Optional integer for the number of chunks to process. If NULL, it defaults to the number of workers.

handler

The progress handler to be used by the progressr package. If NULL and silent is FALSE, it defaults to "txtprogressbar". When silent is TRUE, the handler is set to "void".

restore.defaults

Logical. If TRUE (default), the current future plan is saved and restored upon exit.

zotero

A list with information on the specified Zotero library (e.g., id, API key, collections, and items), Default: NULL

zotero.import

Use CristinWrangler to wrangle metadata into an acceptable format for Zotero, Default: TRUE

zotero.check

Check for Cristin references already stored in Zotero, Default: TRUE

nvi

Filter out non-NVI publications Default: FALSE

remove.na

Cristin contains many, more or less, obscure categories, and not all are (yet) supported. By default these are removed, however, if this option is set to FALSE unsupported categories are treated according to replace.na, Default: TRUE

replace.na

May the odds be in your favor and replace unsupported categories with a predefined itemType if remove.na is set to false, Default: 'book'

force.type

Force all items to a predefined itemType, Default: NULL

silent

c2z is noisy, tell it to be quiet, Default: FALSE

log

A list for storing log elements, Default: list()

Details

Please see #' https://oeysan.github.io/c2z/

Value

A list with (exported) items from Cristin

See Also

http_error, GET, RETRY tail, head slice

Examples

# Simple `Cristin` search by id
  example <- Cristin(id = "840998")

  # Print index using `ZoteroIndex`
  if (any(nrow(example$results))) {
    ZoteroIndex(example$results) |>
      dplyr::select(name) |>
      print(width = 80)
  }

Check for supported export formats from Cristin to Zotero

Description

Used to filter Cristin categories that are not supported

Usage

CristinSupported(
  data = NULL,
  zotero.check = TRUE,
  items = NULL,
  remove.na = TRUE,
  replace.na = "book",
  force.type = NULL,
  remove.duplicates = TRUE,
  silent = FALSE,
  log = list()
)

Arguments

data

Zotero-type matrix, Default: NULL

zotero.check

Should the function look for duplicates?, Default: TRUE

items

Items in library to check for

remove.na

Cristin contains many, more or less, obscure categories, and not all are (yet) supported. By default these are removed, however, if this option is set to FALSE unsupported categories are treated according to replace.na, Default: TRUE

replace.na

May the odds be in your favor and replace unsupported categories with a predefined itemType if remove.na is set to false, Default: 'book'

force.type

Force all items to a predefined itemType, Default: NULL

remove.duplicates

Remove duplicates if TRUE, Default: TRUE

silent

c2z is noisy, tell it to be quiet, Default: FALSE

log

A list for storing log elements, Default: list()

Details

Please see https://oeysan.github.io/c2z/

Value

Zotero supported items with unsupported categories as NA

See Also

tibble

Examples

# Supported Cristin items
print(CristinSupported(), n = 5)

Wrangle Cristin metadata into Zotero-type format

Description

Converts Cristin metadata into a Zotero-style tibble.

Usage

CristinWrangler(data, meta = list(), use.identifiers = TRUE)

Arguments

data

Tibble containing metadata from Cristin

meta

A list for storing data elements, Default: list()

use.identifiers

Use if ISBN/DOI identifiers if enabled, Default: TRUE

Details

Please see https://oeysan.github.io/c2z/

Value

A Zotero-type tibble.


Wrangle CrossRef metadata into Zotero-type format

Description

Query CrossRef by DOI and fetch metadata

Usage

DoiCrossref(data, meta = list(), use.json = TRUE, silent = TRUE, log = list())

Arguments

data

XML data from CrossRef containing metadata

meta

A list collecting all metadata used to create , Default: list()

use.json

Use either json (TRUE) or XML (FALSE), Default: TRUE

silent

c2z is noisy, tell it to be quiet, Default: TRUE

log

A list for storing log elements, Default: list()

Details

Please see https://oeysan.github.io/c2z/

Value

A Zotero-type matrix (tibble)

Examples

# `DoiCrossref` is called from `ZoteroDoi` (if item found)
  example <- ZoteroDoi("10.1126/sciadv.abd1705")

  # Print index using `ZoteroIndex`
  if (!is.null(example$data)) {
    ZoteroIndex(example$data) |>
      dplyr::select(name) |>
      print(width = 80)

    # Display catalog
    example$data$libraryCatalog
  }

Wrangle DataCite metadata into Zotero-type format

Description

Query DataCite by DOI and fetch metadata

Usage

DoiDatacite(data, meta = list(), silent = TRUE, log = list())

Arguments

data

XML data from DataCite containing metadata

meta

A list collecting all metadata used to create , Default: list()

silent

c2z is noisy, tell it to be quiet, Default: TRUE

log

A list for storing log elements, Default: list()

Details

Please see https://oeysan.github.io/c2z/

Value

A Zotero-type matrix (tibble)

Examples

# `DoiDatacite` is called from `ZoteroDoi` (if item found)
  example <- ZoteroDoi("10.17605/OSF.IO/7HZ4P")

  # Use `ZoteroIndex` to print
  # Print index using `ZoteroIndex`
  if (any(nrow(example$data))) {
    ZoteroIndex(example$data) |>
      dplyr::select(name) |>
      print(width = 80)

    # Display catalog
    example$data$libraryCatalog
  }

Process data with Parallel Execution and Row/Chunk Processing

Description

This function processes a tibble (or data frame) in parallel using the future package along with progressr for progress reporting. The data is split into chunks via a helper function SplitData. Depending on the by.rows flag, each chunk is processed either row-by-row (using lapply) or as an entire chunk. In either case, the processed results are bound into a single tibble.

Usage

ProcessData(
  data,
  func,
  by.rows = TRUE,
  min.multisession = 1,
  n.workers = NULL,
  n.chunks = NULL,
  limit = 100,
  use.multisession = TRUE,
  start.message = NULL,
  end.message = NULL,
  restore.defaults = TRUE,
  handler = NULL,
  silent = FALSE,
  log = list(),
  ...
)

Arguments

data

Data to be processed.

func

A function that processes either a single row (if by.rows = TRUE) or an entire chunk (if by.rows = FALSE). Additional arguments are passed to func via ....

by.rows

Logical. If TRUE, func is applied to each row individually within each chunk; if FALSE, func is applied to the entire chunk. Default is TRUE.

min.multisession

Integer. The minimum number of rows in data required to use multisession (parallel execution). If nrow(data) is less than this value, parallel processing is disabled. Default is 1.

n.workers

Integer. The number of workers to use for parallel processing. Defaults to max(1, future::availableCores() - 1).

n.chunks

Integer. The number of chunks into which the data is split. If NULL, it defaults to the number of workers.

limit

Integer. If (nrow(data) / limit) is less than or equal to n.workers, the data is split into n.chunks; otherwise, it is split using limit. Default is 100.

use.multisession

Logical. If TRUE (default) parallel processing is used; otherwise, sequential processing is employed.

start.message

Optional character string. A custom message to log at the start of processing.

end.message

Optional character string. A custom message to log at the end of processing.

restore.defaults

Logical. If TRUE (default), the original future plan and progress handlers are restored after processing.

handler

Character string. The progress handler to be used by the progressr package. Defaults to "txtprogressbar" unless silent is TRUE.

silent

Logical. If TRUE, progress messages and logging are suppressed. Default is FALSE.

log

List. An initial log (default is an empty list) to which log messages are appended.

...

Additional arguments passed to the processing function func.

Details

The function first checks if the data has enough rows to warrant parallel processing. It then determines the number of workers and chunks and splits the data using the helper function SplitData. The processing is executed with future.apply::future_lapply in parallel. If by.rows is TRUE, each row within a chunk is processed individually and then bound together using dplyr::bind_rows; if by.rows is FALSE, the entire chunk is processed at once. Finally, all chunk results are combined into a single tibble.

Value

A list with two components:

results

A tibble resulting from binding all processed rows from each chunk.

log

A list of log messages generated during processing.

Examples

## Not run: 
example.result <- ProcessData(
  data =  tibble::tibble(
    key = LETTERS[1:3],
    value = seq(3)
  ),
  func = \(data) {
    data$value <- data$value * 10
    data
  },
  by.rows = FALSE,
  min.multisession = 10,
  n.workers = 4,
  n.chunks = 4,
  limit = 100,
  use.multisession = TRUE,
  start.message = "Starting example data processing",
  end.message   = "Finished example data processing",
  handler = "txtprogressbar",
  silent = FALSE
)
# The result is a single tibble.
processed.tibble <- example.result$results
process.log <- example.result$log
if (any(nrow(processed.tibble))) print(processed.tibble)

## End(Not run)

Process Data with Optional Parallel Execution and Progress Reporting

Description

This function executes a provided expression with progress reporting and optional parallel processing using the future and progressr packages. It logs the start and end times of the process along with a runtime message and supports custom logging, progress handlers, and execution plans.

Usage

Processing(
  func = substitute(NULL),
  n = NULL,
  start.message = NULL,
  end.message = NULL,
  use.multisession = TRUE,
  n.workers = NULL,
  n.chunks = NULL,
  handler = NULL,
  restore.defaults = TRUE,
  silent = FALSE,
  log = list()
)

Arguments

func

An expression (or a quoted function call) to be evaluated. The default is substitute(NULL). It is evaluated in the parent frame.

n

Optional integer indicating the number of items to be processed, used solely for logging purposes.

start.message

Optional character string specifying a custom start message. If NULL, a default message is generated based on the processing type and, if provided, the number of items.

end.message

Optional character string specifying a custom end message. If NULL, a runtime message is generated showing the elapsed time.

use.multisession

Logical. If TRUE (default), parallel processing using multisession is employed; otherwise, processing is sequential.

n.workers

Optional integer for the number of workers to be used in multisession mode. If NULL, it defaults to the number of available cores minus one (with a minimum of one).

n.chunks

Optional integer for the number of chunks to process. If NULL, it defaults to the number of workers.

handler

The progress handler to be used by the progressr package. If NULL and silent is FALSE, it defaults to "txtprogressbar". When silent is TRUE, the handler is set to "void".

restore.defaults

Logical. If TRUE (default), the current future plan is saved and restored upon exit.

silent

Logical. If TRUE, progress output is suppressed. Default is FALSE.

log

A list to collect log messages. Default is an empty list.

Details

The function begins by determining whether to use multisession (parallel) or sequential processing. It then logs the start time using a helper function, LogCat, and sets up the future plan accordingly. If restore.defaults is TRUE, the original plan is restored after execution.

A progress handler is configured via the progressr package. The provided expression is evaluated with progress reporting enabled. Upon completion, the function computes the elapsed time (with millisecond precision) and logs an end message. Finally, it returns a list containing the result of the evaluated expression and the log of messages.

Value

A list with the following components:

result

The output resulting from the evaluation of func.

log

A list of log messages including start and end timestamps along with associated messages.

Examples

## Not run: 
  # Example: Process data with a simple sleep expression using multisession processing
  result <- Processing(
    func = quote({
      Sys.sleep(2)  # simulate a time-consuming task
      "Task Completed"
    }),
    n = 100,
    use.multisession = TRUE
  )
  print(result$result)
  print(result$log)

## End(Not run)

Upsert and Update Data Frames

Description

Combines two data frames by updating rows in x with values from y based on a common key, and inserting new rows from y that are not present in x. The function first harmonizes the column structures of both data frames by adding missing columns and coercing types as necessary.

Usage

UpdateInsert(x, y, key = "key", check.missing = FALSE)

Arguments

x

A data frame to be updated.

y

A data frame containing new values to update x. Must include the column specified by key.

key

A character string specifying the unique key column used for matching rows. Defaults to "key".

check.missing

Logical; if TRUE, performs a cell-by-cell update only when the new value is not missing. Missing values are defined as NA for atomic types or an empty list for list columns. If FALSE, a standard upsert is performed using dplyr::rows_upsert. Defaults to FALSE.

Details

The function works in several steps:

  1. It computes the union of all column names from x and y and adds any missing columns to both data frames using the internal helper function AddColumns. Missing columns are filled with an appropriate NA value based on their type.

  2. Both x and y are reordered to have the same column order.

  3. For each common column (excluding the key), if x's column is entirely NA or if the data types differ, coercion is performed to ensure compatibility between x and y.

  4. When check.missing is TRUE, the function iterates over each common key and updates each cell in x only if the corresponding cell in y is not missing. Otherwise, it uses dplyr::rows_upsert to perform a standard upsert.

  5. New rows present in y but not in x are appended.

Value

A data frame resulting from updating x with values from y.

Examples

## Not run: 
  # Example data frames:
  df1 <- data.frame(
    key = 1:3,
    a = c(NA, 2, NA),
    b = c("x", NA, "z"),
    stringsAsFactors = FALSE
  )

  df2 <- data.frame(
    key = c(2, 3, 4),
    a = c(5, 6, 7),
    b = c("y", "w", "v"),
    stringsAsFactors = FALSE
  )

  # Standard upsert (check.missing = FALSE):
  result <- UpdateInsert(df1, df2, key = "key", check.missing = FALSE)

  # Cell-by-cell update (check.missing = TRUE):
  result <- UpdateInsert(df1, df2, key = "key", check.missing = TRUE)

## End(Not run)

Connect to Zotero API

Description

Wrapper to connect with the Zotero API and the main functions of *c2z*

Usage

Zotero(
  collection.names = NULL,
  collection.key = NULL,
  collection.path = NULL,
  item.key = NULL,
  library = FALSE,
  case.insensitive = TRUE,
  ancestor = FALSE,
  recursive = FALSE,
  create = FALSE,
  limit = 100,
  start = 0,
  search.collections = TRUE,
  get.collections = TRUE,
  get.items = TRUE,
  item.type = NULL,
  all.results = TRUE,
  max.results = NULL,
  collections = NULL,
  items = NULL,
  attachments = NULL,
  metadata = NULL,
  doi = NULL,
  isbn = NULL,
  export = FALSE,
  csl.type = NULL,
  csl.name = "style",
  format = "biblatex",
  save.data = FALSE,
  save.path = NULL,
  bib.name = "references",
  library.type = NULL,
  linkwrap = 1,
  style = "apa",
  locale = "en-US",
  copy = FALSE,
  copy.collections = TRUE,
  copy.items = TRUE,
  copy.extras = TRUE,
  remove.missing = TRUE,
  change.library = FALSE,
  copy.user = TRUE,
  copy.id = NULL,
  copy.api = NULL,
  post = FALSE,
  post.collections = TRUE,
  post.items = TRUE,
  post.attachments = TRUE,
  post.limit = 50,
  post.token = FALSE,
  delete = FALSE,
  delete.collections = FALSE,
  delete.items = FALSE,
  delete.limit = 50,
  ragnarok = FALSE,
  user = TRUE,
  index = FALSE,
  id = NULL,
  token = NULL,
  token.api = NULL,
  api = NULL,
  force = FALSE,
  base.url = "https://api.zotero.org",
  silent = FALSE,
  zotero = NULL,
  log = list()
)

Arguments

collection.names

Vector of collection names to create or search for, Default: NULL

collection.key

A specified collection key, Default: NULL

collection.path

Vector of nested collection keys, Default: NULL

item.key

A specified item key, Default: NULL

library

Use 'ZoteroLibrary' to fetch collections and items, Default: FALSE

case.insensitive

Disregard letter casing when searching for collections, Default: TRUE

ancestor

Trace the lineage of a collection (i.e., find the top-level collection), Default: FALSE

recursive

Find all nested collections, Default: FALSE

create

Create missing collections, Default: FALSE

limit

Number of results per query (max 100), Default: 100

start

Starting position of query (0 = first result), Default: 0

search.collections

Search all collections if collection.key fails, Default: TRUE

get.collections

Fetch collections, Default: TRUE

get.items

Fetch items, Default: TRUE

item.type

Items to search for (NULL = everything), Default: NULL

all.results

Find all results in query, Default: TRUE

max.results

Do you need a limit?, Default: NULL

collections

Predefined collections (as tibble), Default: NULL

items

Predefined metadata (as tibble), Default: NULL

attachments

Predefined attachments (as tibble), Default: NULL

metadata

Predefined metadata in Zotero-format, Default: NULL

doi

Use ZoteroDoi to fetch DOI metadata, Default: NULL

isbn

Use ZoteroIsbn to fetch ISBN metadata, Default: NULL

export

Use 'ZoteroExport' to export items, Default: FALSE

csl.type

Specify a CSL type to Official repository for Citation Style Language (CSL), Default: NULL

csl.name

Name of saved CSL file, Default: 'style'

format

Export format of Zotero items, Default: 'biblatex'

save.data

Save data (e.g., bibliography) to disk, Default: FALSE

save.path

Location to store data on disk, Default: NULL

bib.name

Name of exported bibliography, Default: 'references'

library.type

Commma-separated data from Zotero (i.e., data, bib, citation), Default: NULL

linkwrap

Set URL (e.g., DOI) as HTML link (1 = yes), Default: 1

style

Citation style to use for appended bibliography and/or citations, Default: apa

locale

Desired language format of bibliography, Default: 'en-US'

copy

Use 'ZoteroCopy' to delete collections and/or items, Default: FALSE

copy.collections

Try to copy specified collections, Default: TRUE

copy.items

Try to copy specified items?, Default: TRUE

copy.extras

Try to copy specified extras (i.e., attachments and notes)?, Default: TRUE

remove.missing

Deleted missing extras, Default: TRUE

change.library

Stage changing of library (e.g., from a group to a personal library), Default: FALSE

copy.user

New user type (The functions will use 'group' as prefix if FALSE), Default: TRUE

copy.id

New id, Default: NULL

copy.api

New API key. Set API to 'NA' if key is not needed, Default: NULL

post

Use 'ZoteroPost' to post collections and/or items, Default: FALSE

post.collections

Try to copy specified collections, Default: TRUE

post.items

Try to copy specified items?, Default: TRUE

post.attachments

Try to copy specified extras (i.e., attachments and notes)?, Default: TRUE

post.limit

Number of collections/items to post per request (max 50), Default: 50

post.token

Use Zotero-Write-Token (TRUE) or If-Unmodified-Since-Version (FALSE), Default: FALSE

delete

Use 'ZoteroDelete' to delete collections and/or items, Default: FALSE

delete.collections

Try to delete specified collections, Default: TRUE

delete.items

Try to delete specified items?, Default: TRUE

delete.limit

Number of collections/items to delete per request (max 50), Default: 50

ragnarok

Delete EVERYTHING in the specified library, Default: FALSE

user

User type (The functions will use 'group' as prefix if FALSE), Default: TRUE

index

Create an index of items, Default: FALSE

id

User or group ID, Default: NULL

token

Name of user or group token as defined in '.Renviron', Default: NULL

token.api

Name of API token as defined in '.Renviron', Default: NULL

api

API key to connect with the Zotero library. Set API to 'NA' if key is not needed. See Zotero API, Default: NULL

force

Force is seldom wise, but sometimes..., Default: FALSE

base.url

Base url of the Zotero API, Default: 'https://api.zotero.org'

silent

c2z is noisy, tell it to be quiet, Default: FALSE

zotero

A list with information on the specified Zotero library (e.g., id, API key, collections, and items), Default: NULL

log

A list for storing log elements, Default: list()

Details

Please see https://oeysan.github.io/c2z/

Value

A list with information on the specified Zotero library (e.g., id, API key, collections, and items)

See Also

http_error, GET

Examples

# Create the default Zotero list
example <- Zotero(id = "9913421", api = "RqlAmlH5l1KPghfCseAq1sQ1")
# Print the interesting pars of an otherwise empty list
print(tail(example,5))

Add items to Zotero list

Description

Use identifiers or predefined data to add to the Zotero list

Usage

ZoteroAdd(zotero, metadata = NULL, doi = NULL, isbn = NULL, silent = FALSE)

Arguments

zotero

A list with information on the specified Zotero library (e.g., id, API key, collections, and items)

metadata

Predefined metadata in Zoter-format, Default: NULL

doi

Use ZoteroDoi to fetch DOI metadata, Default: NULL

isbn

Use ZoteroIsbn to fetch ISBN metadata, Default: NULL

silent

c2z is noisy, tell it to be quiet, Default: FALSE

Details

Please see https://oeysan.github.io/c2z/

Value

Will add data to the Zotero list

Examples

# Add items from `ZoteroIsbn` to the default Zotero list
  example <- ZoteroAdd(
    Zotero(
      id = "9913421",
      api = "RqlAmlH5l1KPghfCseAq1sQ1"
    ),
    isbn = "978-1529797138"
  )
  # Print index using `ZoteroIndex`
  if (any(nrow(example$items))) {
    ZoteroIndex(example$items) |>
      dplyr::select(name) |>
      print(width = 80)
  }

Check Zotero Library for Duplicates

Description

Removes references from the input dataset that are duplicates already added to Zotero, preserving only those references that have been modified since their addition.

Usage

ZoteroCheck(
  data,
  id,
  id.type,
  created,
  last.modified,
  items,
  remove.duplicates = TRUE,
  silent = FALSE,
  log = list()
)

Arguments

data

A tibble containing metadata (e.g., from Cristin)

id

A string specifying the column name in data that contains the unique identifier (e.g., "cristin_result_id")

id.type

A string specifying the type of metadata as stored in the Zotero extra field (e.g., "Cristin")

created

A string specifying the column name in data containing the creation date in UNIX timestamp format (e.g., "created")

last.modified

A string specifying the column name in data containing the last modification date in UNIX timestamp format (e.g., "last_modified")

items

A data frame or tibble representing items in the Zotero library to check against

remove.duplicates

Logical. If TRUE, duplicates that have not been modified are removed. Default is TRUE.

silent

Logical. If TRUE, suppresses verbose output. Default is FALSE.

log

A list for storing log messages. Default is an empty list.

Details

For more details, see c2z documentation.

Value

A list with two elements: data, a tibble containing non-duplicated items, and log, the updated log list.

See Also

arrange, coalesce, bind_rows, filter

Examples

## Not run: 
  # Simple Cristin search by id
  cristin.data <- Cristin(
    id = "840998",
    zotero.import = FALSE
  )

  # Checking Zotero library for duplicates
  result <- ZoteroCheck(
    data = cristin.data$result,
    id = "cristin_result_id",
    id.type = "Cristin",
    created = "created",
    last.modified = "last_modified",
    items = Zotero(
      user = FALSE,
      id = "4827927",
      api = "RqlAmlH5l1KPghfCseAq1sQ1",
      library = TRUE,
      silent = TRUE
    )$items
  )

## End(Not run)

Copy collections and items from a Zotero library

Description

Replace key identifiers with new ones while keeping existing structure and relationship between collections and items

Usage

ZoteroCopy(
  zotero,
  copy.collections = TRUE,
  copy.items = TRUE,
  copy.extras = TRUE,
  remove.missing = TRUE,
  change.library = FALSE,
  copy.user = TRUE,
  copy.id = NULL,
  copy.api = NULL,
  silent = FALSE
)

Arguments

zotero

A list with information on the specified Zotero library (e.g., id, API key, collections, and items)

copy.collections

Try to copy specified collections, Default: TRUE

copy.items

Try to copy specified items?, Default: TRUE

copy.extras

Try to copy specified extras (i.e., attachments and notes)?, Default: TRUE

remove.missing

Deleted missing extras, Default: TRUE

change.library

Stage changing of library (e.g., from a group to a personal library), Default: FALSE

copy.user

New user type (The functions will use 'group' as prefix if FALSE), Default: TRUE

copy.id

New id, Default: NULL

copy.api

New API key, Default: NULL

silent

c2z is noisy, tell it to be quiet, Default: FALSE

Details

Please see https://oeysan.github.io/c2z/

Value

A list with information on the specified Zotero library (e.g., copied collections and items)

See Also

GET mutate, case_when, filter, select, across, arrange pmap all_of

Examples

# Fetching collections and items from default group
  zotero = Zotero(
    user = FALSE,
    id = "4827927",
    api = "RqlAmlH5l1KPghfCseAq1sQ1",
    library = TRUE
  )

  # Display collections
  if (any(nrow(zotero$collections))) {
    zotero$collections |>
      dplyr::select(key, version, parentCollection) |>
      print(width = 80)
  }

  # Display items
  if (any(nrow(zotero$items))) {
    zotero$items |>
      dplyr::select(key, version) |>
      print(width = 80)
  }

  # Copy items
  example <- ZoteroCopy(
    zotero,
  )

  # Display collections
  if (any(nrow(example$collections))) {
    example$collections |>
      dplyr::select(key, version, parentCollection) |>
      print(width = 80)
  }

  # Display items
  if (any(nrow(example$items))) {
    example$items |>
      dplyr::select(key, version) |>
      print(width = 80)
  }

Wrangle CRAN metadata into Zotero-type format

Description

Query CRAN by name and fetch metadata

Usage

ZoteroCran(id, meta = list(), silent = TRUE, log = list())

Arguments

id

name of R package

meta

A list collecting all metadata used to create , Default: list()

silent

c2z is noisy, tell it to be quiet, Default: TRUE

log

A list for storing log elements, Default: list()

Details

Please see https://oeysan.github.io/c2z/

Value

A Zotero-type matrix (tibble)

See Also

RETRY reexports

Examples

# Search cran for package `dplyr`
  example <- ZoteroCran(c("dplyr", "jsonlite", "httr"))

  # Print index using `ZoteroIndex`
  if (any(nrow(example$data))) {
  ZoteroIndex(example$data) |>
    dplyr::select(name) |>
    print(width = 80)
  }

Delete collections and items from a Zotero library

Description

Cleaning the Zotero library

Usage

ZoteroDelete(
  zotero,
  delete.collections = FALSE,
  delete.items = FALSE,
  delete.limit = 50,
  force = FALSE,
  ragnarok = FALSE,
  silent = FALSE
)

Arguments

zotero

A list with information on the specified Zotero library (e.g., id, API key, collections, and items)

delete.collections

Try to delete specified collections, Default: TRUE

delete.items

Try to delete specified items?, Default: TRUE

delete.limit

Number of collections/items to delete per request (max 50), Default: 50

force

Force is seldom wise, but sometimes..., Default: FALSE

ragnarok

Delete EVERYTHING in the specified library, Default: FALSE

silent

c2z is noisy, tell it to be quiet, Default: FALSE

Details

Please see https://oeysan.github.io/c2z/

Value

A list with information on the specified Zotero library (e.g., deleted collections and items)

See Also

add_headers, RETRY

Examples

# Delete everything in a group
  example <- ZoteroDelete(
    Zotero(
      user = FALSE,
      id = "4988497",
      api = "RqlAmlH5l1KPghfCseAq1sQ1"
    ),
    ragnarok = TRUE,
    force = TRUE
  )

Use DOI to acquire metadata

Description

Connects with doi.org to create metadata

Usage

ZoteroDoi(
  doi,
  meta = list(),
  use.semantic = TRUE,
  check.retraction = TRUE,
  use.json = TRUE,
  silent = TRUE,
  log = list()
)

Arguments

doi

A digital object identifier

meta

A list collecting all metadata used to create , Default: list()

use.semantic

Get metadata (abstract) from Semantic Scholar, Default: FALSE

check.retraction

Check if marked as retracted, Default: TRUE

use.json

Use either json (TRUE) or XML (FALSE), Default: TRUE

silent

c2z is noisy, tell it to be quiet, Default: TRUE

log

A list for storing log elements, Default: list()

Details

Please see https://oeysan.github.io/c2z/

Value

A Zotero-type matrix (tibble)

See Also

http_error, GET, RETRY rename, html_attr, html_text, reexports, html_children, html_name bind, arrange

Examples

# Simple use of `ZoteroDoi`
  example <- ZoteroDoi("10.1126/sciadv.abd1705")

  # Print index using `ZoteroIndex`
  if (any(nrow(example$data))) {
  ZoteroIndex(example$data) |>
    dplyr::select(name) |>
    print(width = 80)
  }

Enhance Zotero Records with External Metadata via Zotero Lookups

Description

This function iterates over a data frame (or tibble) of Zotero records and attempts to enhance each record by retrieving additional metadata from external sources. It uses DOI or ISBN information, via the c2z package, to fetch external metadata and then merges these updates into the original Zotero record. Special handling is provided for records representing book sections.

Usage

ZoteroEnhancer(
  zotero.data,
  external.data = NULL,
  use.doi = TRUE,
  use.semantic = TRUE,
  use.isbn = TRUE
)

Arguments

zotero.data

A data frame (or tibble) containing Zotero records. Each row represents a record that may include fields such as abstractNote, DOI, url, ISBN, key, itemType, pages, and creators.

external.data

Optional. A data frame or list containing pre-fetched external metadata. If provided and non-empty, the function will use this external metadata to update the Zotero records instead of querying the external APIs. Defaults to NULL.

use.doi

Logical; if TRUE (default), the function will attempt to retrieve external metadata using DOI information. Defaults to TRUE.

use.semantic

Logical; if TRUE (default), the function will attempt to retrieve external metadata from Semantic Scholar using DOI information. Defaults to TRUE.

use.isbn

Logical; if TRUE (default), the function will attempt to retrieve external metadata using ISBN information when DOI retrieval is not successful. Defaults to TRUE.

Details

For each record in zotero.data, the function performs the following steps:

  1. If external.data is provided and non-empty, that data is used to update the record.

  2. Otherwise, the function skips processing the record if an abstract already exists.

  3. It then attempts to extract a DOI from the DOI field, or if missing, from the url field.

  4. The ISBN field is processed by removing spaces and extracting the first value (in case of comma separation).

  5. If a valid DOI is found and use.doi is TRUE, external metadata is retrieved using c2z::ZoteroDoi(). Otherwise, if an ISBN is available and use.isbn is TRUE, metadata is retrieved using c2z::ZoteroIsbn().

  6. Once external metadata is successfully retrieved, an internal helper function UpdateTibble is called. This helper function merges the external metadata into the original record. For book sections, additional adjustments are made to handle creator information, pages, and edition fields.

  7. Finally, the enhanced record is merged back into the original data frame using UpdateInsert().

Value

A data frame containing the enhanced Zotero records with external metadata merged into the original records.

Examples

## Not run: 
  # Enhance Zotero records using DOI/ISBN lookup:
  example <- Cristin("762394", silent = TRUE)$results
  print(example$libraryCatalog)
  example$DOI <- "https://doi.org/10.22358/jafs/74164/2007"
  enhanced.data <- ZoteroEnhancer(example)
  print(enhanced.data$libraryCatalog)

## End(Not run)

Export Zotero items to bibliography

Description

Export Zotero items to a specified format (e.g., BibLaTeX) using a CSL format (e.g., APA7)

Usage

ZoteroExport(
  zotero,
  csl.type = NULL,
  csl.name = "style",
  locale = "en-US",
  format = "biblatex",
  bib.name = "references",
  save.data = FALSE,
  save.path = NULL,
  silent = FALSE
)

Arguments

zotero

A list with information on the specified Zotero library (e.g., id, API key, collections, and items)

csl.type

Specify a CSL type to Official repository for Citation Style Language (CSL), Default: NULL

csl.name

Name of saved CSL file, Default: 'style'

locale

Desired language format of bibliography, Default: 'en-US'

format

Export format of Zotero items, Default: 'biblatex'

bib.name

Name of exported bibliography, Default: 'references'

save.data

Save data (e.g., bibliography) to disk, Default: FALSE

save.path

Location to store data on disk, Default: NULL

silent

c2z is noisy, tell it to be quiet, Default: FALSE

Details

Please see https://oeysan.github.io/c2z/

Value

A list with information on the specified Zotero library (e.g., exported items, bibliography and citations)

See Also

select where

Examples

# Define Zotero list according to default group
  zotero = Zotero(
    user = FALSE,
    id = "4827927",
    api = "RqlAmlH5l1KPghfCseAq1sQ1",
    item.type = "-attachment || note",
    max.result = 1,
    library = TRUE
  )

  # Export 1 items from the default group
  example <- ZoteroExport(
    zotero
  )
  # Display exported
  cat(example$export, fill = 80)

Make a Zotero friendly format of input data

Description

Make a Zotero friendly format of input data, will add a zotero key.

Usage

ZoteroFormat(
  data = NULL,
  format = NULL,
  prefix = NULL,
  check.structure = FALSE,
  fix.columns = TRUE,
  silent = FALSE
)

Arguments

data

A list of metadata or something else, Default: NULL

format

The format of the input data (e.g., 'JSON', 'versions', 'keys). , Default: NULL

prefix

Add a prefix to the metadata (e.g., user/userID), Default: NULL

check.structure

Check that the structure of a data frame is correct according to the Zotero type, Default: FALSE

fix.columns

Remove columns not part of the Zotero type, Default: TRUE

silent

c2z is noisy, tell it to be quiet, Default: TRUE

Value

A zotero friendly tibble if requested otherwise format the data according to format.

See Also

tibble, as_tibble toJSON, fromJSON mutate_all, na_if, mutate, across, reexports, select map

Examples

ZoteroFormat(
    list(title = "This is a test", itemType = "document")
  )

Get collections and items from a Zotero library

Description

Get

Usage

ZoteroGet(
  zotero,
  use.collection = TRUE,
  use.item = FALSE,
  append.collections = FALSE,
  append.items = FALSE,
  append.top = FALSE,
  append.file = FALSE,
  custom.url = NULL,
  open.query = NULL,
  limit = 100,
  start = 0,
  format = "json",
  item.keys = NULL,
  collection.keys = NULL,
  item.type = NULL,
  library.type = NULL,
  linkwrap = 1,
  style = "apa",
  locale = "en-US",
  all.results = TRUE,
  max.results = NULL,
  result.type = NULL,
  force = FALSE,
  silent = FALSE
)

Arguments

zotero

A list with information on the specified Zotero library (e.g., id, API key, collections, and items)

use.collection

Use collection key if present in Zotero list, Default: TRUE

use.item

Use item key if present in Zotero list, Default: FALSE

append.collections

Append '/collections/' to Zotero API url, Default: FALSE

append.items

Append '/items/' to Zotero API url, Default: FALSE

append.top

Append '/top/' to Zotero API url, Default: FALSE

append.file

Append '/file/' to Zotero API url, Default: FALSE

custom.url

Use a custom Zotero API url, Default: NULL

open.query

Use your own query, Default: NULL

limit

Number of results per query (max 100), Default: 100

start

Starting position of query (0 = first result), Default: 0

format

Format of response from the Zotero API, Default: 'json'

item.keys

Specified vector of items keys, Default: NULL

collection.keys

Specified vector of collection keys, Default: NULL

item.type

Items to search for (NULL = everything), Default: NULL

library.type

Commma-separated data from Zotero (i.e., data, bib, citation), Default: NULL

linkwrap

Set URL (e.g., DOI) as HTML link (1 = yes), Default: 1

style

Citation style to use for appended bibliography and/or citations, Default: apa

locale

Desired language format of bibliography, Default: 'en-US'

all.results

Find all results in query, Default: TRUE

max.results

Do you need a limit?, Default: NULL

result.type

Pointless linguistics to display result type (default = 'result'), Default: NULL

force

Force is seldom wise, but sometimes..., Default: FALSE

silent

c2z is noisy, tell it to be quiet, Default: FALSE

Details

Please see https://oeysan.github.io/c2z/

Value

A list with information on the specified Zotero library (e.g., collections and items)

See Also

RETRY

Examples

# Define Zotero list according to default setings
  zotero = Zotero(
    user = FALSE,
    id = "5250382",
    api = "RqlAmlH5l1KPghfCseAq1sQ1"
  )

  # Query default group Zotero library for 1 item
  example <- ZoteroGet(
    zotero,
    max.results = 1
  )

  # Print index using `ZoteroIndex`
  if (any(nrow(example$results))) {
  ZoteroIndex(example$results) |>
    dplyr::select(name) |>
    print(width = 80)
  }

Wrangle regjeringen.no metadata into Zotero-type format

Description

Query regjeringen by search word and type and fetch metadata

Usage

ZoteroGov(search, type = "NOU", meta = list(), silent = TRUE, log = list())

Arguments

search

Search term (e.g., 2018: 2)

type

type of query (e.g., white paper, official norwegian reports), Default: "NOU"

meta

A list collecting all metadata used to create , Default: list()

silent

c2z is noisy, tell it to be quiet, Default: TRUE

log

A list for storing log elements, Default: list()

Details

Please see https://oeysan.github.io/c2z/

Value

A Zotero-type matrix (tibble)

See Also

RETRY reexports bind, arrange

Examples

# Search the default entity, Norwegian official reports in regjeringen.no
  example <- ZoteroGov("2001:4")
  # Print index using `ZoteroIndex`
  if (any(nrow(example$data))) {
  ZoteroIndex(example$data) |>
    dplyr::select(name) |>
    print(width = 80)
  }

Create an index of Zotero items

Description

The function creates a index containing key information about the present Zotero items

Usage

ZoteroIndex(data)

Arguments

data

Tibble containing Zotero-type metadata (e.g., from Cristin)

Details

Please see https://oeysan.github.io/c2z/

Value

A tibble

See Also

filter, mutate, across, na_if, case_when, arrange, group_by, context, select everything pmap

Examples

# Access the default group library
  example = Zotero(
    user = FALSE,
    id = "4827927",
    api = "RqlAmlH5l1KPghfCseAq1sQ1",
    library = TRUE
  )
  # Print index using `ZoteroIndex`
  if (any(nrow(example$items))) {
  ZoteroIndex(example$items) |>
    dplyr::select(name) |>
    print(width = 80)
  }

Search libraries using ISBN or MMS ID

Description

Query libraries using ISBN (or MMS ID) and fetch metadata

Usage

ZoteroIsbn(keys, meta = list(), silent = TRUE, log = list())

Arguments

keys

Keys to search with (e.g., ISBN or MMS ID)

meta

A list collecting all metadata used to create , Default: list()

silent

c2z is noisy, tell it to be quiet, Default: TRUE

log

A list for storing log elements, Default: list()

Details

Please see https://oeysan.github.io/c2z/

Value

A Zotero-type matrix (tibble)

See Also

rename, html_children, html_attr, html_text, reexports bind, distinct, arrange tibble RETRY setNames toJSON, fromJSON

Examples

# Search libraries for ISBN metadata
  example <- ZoteroIsbn("978-1529797138")

  # Print index using `ZoteroIndex`
  if (any(nrow(example$data))) {
  ZoteroIndex(example$data) |>
    dplyr::select(name) |>
    print(width = 80)
  }

Create Zotero key or write token

Description

Create an identifier for Zotero items/collections or a write token to library

Usage

ZoteroKey(token = FALSE)

Arguments

token

Create a write token, Default: FALSE

Details

Please see https://oeysan.github.io/c2z/

Value

Will return a 8 character Zotero key or 32 character write token

Examples

# Create a Zotero key
key <- ZoteroKey()
# Create a write token
token <- ZoteroKey(TRUE)

Access the Zotero library

Description

The function uses information stored in the 'zotero' list to access specified collections and items in the Zotero library

Usage

ZoteroLibrary(
  zotero,
  case.insensitive = TRUE,
  ancestor = FALSE,
  recursive = FALSE,
  create = FALSE,
  limit = 100,
  start = 0,
  search.collections = TRUE,
  get.collections = TRUE,
  get.items = TRUE,
  item.type = NULL,
  all.results = TRUE,
  max.results = NULL,
  library.type = NULL,
  linkwrap = 1,
  style = "apa",
  locale = "en-US",
  force = FALSE,
  silent = FALSE
)

Arguments

zotero

A list with information on the specified Zotero library (e.g., id, API key, collections, and items)

case.insensitive

Disregard letter casing when searching for collections, Default: TRUE

ancestor

Trace the lineage of a collection (i.e., find the top-level collection), Default: FALSE

recursive

Find all nested collections, Default: FALSE

create

Create missing collections, Default: FALSE

limit

Number of results per query (max 100), Default: 100

start

Starting position of query (0 = first result), Default: 0

search.collections

Search all collections if collection.key fails, Default: TRUE

get.collections

Fetch collections, Default: TRUE

get.items

Fetch items, Default: TRUE

item.type

Items to search for (NULL = everything), Default: NULL

all.results

Find all results in query, Default: TRUE

max.results

Do you need a limit?, Default: NULL

library.type

Commma-separated data from Zotero (i.e., data, bib, citation), Default: NULL

linkwrap

Set URL (e.g., DOI) as HTML link (1 = yes), Default: 1

style

Citation style to use for appended bibliography and/or citations, Default: apa

locale

Desired language format of bibliography, Default: 'en-US'

force

Force is seldom wise, but sometimes..., Default: FALSE

silent

c2z is noisy, tell it to be quiet, Default: FALSE

Details

Please see https://oeysan.github.io/c2z/

Value

A list with information on the specified Zotero library (e.g., collections and items)

See Also

toJSON, fromJSON distinct, arrange tibble

Examples

# Access the default group library
  example <- ZoteroLibrary(
    Zotero(
      user = FALSE,
      id = "4827927",
      api = "RqlAmlH5l1KPghfCseAq1sQ1"
    )
  )
  # Print index using `ZoteroIndex`
  if (any(nrow(example$items))) {
    ZoteroIndex(example$items) |>
      dplyr::select(name) |>
      print(width = 80)
  }

Search or match items using CrossRef

Description

Use the CrossRef API to match data (e.g., Cristin metadata with Crossref metadata) or search by title, authors and date

Usage

ZoteroMatch(
  title,
  authors,
  date,
  haystack = NULL,
  haystack.size = 3,
  crossref.search = FALSE,
  autosearch = FALSE,
  cristin.data = NULL,
  external.data = NULL,
  polite = TRUE,
  silent = FALSE,
  use.semantic = FALSE,
  log = list()
)

Arguments

title

Title of reference

authors

creators of the reference

date

publication date of the reference

haystack

Potential matches for search term (i.e., needle), Default: NULL

haystack.size

Number of items in the haystack, Default: 3

crossref.search

Search CrossRef if needle not found in haystack, Default: FALSE

autosearch

Match automatically or compare needle with haystack, Default: FALSE

cristin.data

Metadata from Cristin, Default: NULL

external.data

Metadata from external source (e.g., CrossRef), Default: NULL

polite

Will use an email stored in '.Renviron', Default: TRUE

silent

Running silent, running deep, Default: FALSE

use.semantic

Prefer metadata from Semantic Scholar, Default: FALSE

log

A list for storing log elements, Default: list()

Details

Please see https://oeysan.github.io/c2z/

Value

A Zotero-type matrix (tibble) if match is found otherwise NULL

See Also

select, reexports, mutate, coalesce, pull sym RETRY toJSON, fromJSON adist, head map

Examples

# Conduct an autosearch in CrossRef using title, authors and date
  example <- ZoteroMatch(
    title = "Nonreplicable publications",
    authors = "Serra-Garcia & Gneezy",
    date = "2021",
    autosearch = TRUE
  )

  # Print index using `ZoteroIndex`
  if (any(nrow(example$data))) {
  ZoteroIndex(example$data) |>
    dplyr::select(name) |>
    print(width = 80)
  }

Post collections and items to a Zotero library

Description

Create or update collections and items in a specified library

Usage

ZoteroPost(
  zotero,
  post.collections = TRUE,
  post.items = TRUE,
  post.attachments = TRUE,
  post.limit = 50,
  post.token = FALSE,
  force = FALSE,
  silent = FALSE
)

Arguments

zotero

A list with information on the specified Zotero library (e.g., id, API key, collections, and items)

post.collections

Try to copy specified collections, Default: TRUE

post.items

Try to copy specified items?, Default: TRUE

post.attachments

Try to copy specified extras (i.e., attachments and notes)?, Default: TRUE

post.limit

Number of collections/items to post per request (max 50), Default: 50

post.token

Use Zotero-Write-Token (TRUE) or If-Unmodified-Since-Version (FALSE), Default: FALSE

force

Force is seldom wise, but sometimes..., Default: FALSE

silent

c2z is noisy, tell it to be quiet, Default: FALSE

Details

Please see https://oeysan.github.io/c2z/

Value

A list with information on the specified Zotero library (e.g., posted collections and items)

See Also

select, bind, mutate add_headers, RETRY toJSON, fromJSON as_tibble, add_column stack setNames

Examples

# Connect to the public group "c2z_delete"
  # NB! This process can be done using only `Zotero` (see README)
  zotero <- Zotero(
    user = FALSE,
    id = "4988497",
    api = "RqlAmlH5l1KPghfCseAq1sQ1"
  )

  # Create a new collection for POST
  zotero$collections <- tibble::tibble(
    key = ZoteroKey(),
    version = 0,
    name = "Post-test",
    parentCollection = "FALSE"
  )

  # Add item to post using `ZoteroAdd` (and `ZoteroDoi`)
  zotero <- ZoteroAdd(
    zotero,
    doi = "10.1126/sciadv.abd1705"
  )

  # Post a DOI to the public group "c2z_delete"
  post.example <- ZoteroPost(
    zotero,
    post.collections = TRUE,
    post.items = TRUE
  )

  # Delete collections and items using `ZoteroDelete`
  delete.example <- ZoteroDelete(
    post.example,
    delete.collections = TRUE,
    delete.items = TRUE
  )

  # Print index using `ZoteroIndex`
  if (any(nrow(post.example$items))) {
    ZoteroIndex(post.example$items) |>
      dplyr::select(name) |>
      print(width = 80)
  }

List with empty zotero-items

Description

Each tibble in the list represents a zotero-item

Usage

ZoteroTypes(type = NULL, names = TRUE)

Arguments

type

Type of zotero-item, Default: NULL

names

return only column names if set to TRUE, Default: TRUE

Format

A list with 36 tibbles with zero rows and various columns

Details

Used to create Zotero-items from list of metadata

Value

Either list of zotero-items or specified item

Examples

# All zotero-items
names(ZoteroTypes())
# Column names of item-type `book`
ZoteroTypes("book")