Learn R Programming

wikiTools (version 1.2.26)

v_dfVIAF: Flatten VIAF API Data into a Data Frame

Description

Takes a parsed JSON response (as a list) from the Virtual International Authority File (VIAF) API and extracts key bibliographic and biographical fields. It flattens deeply nested and irregular list structures into a clean, single-row-per-record data.frame. Multiple values within a single field (such as titles, occupations, or sources) are collapsed and separated by a pipe (|).

Usage

v_dfVIAF(viaf, check_dateType = TRUE)

Value

A data.frame where each row represents a VIAF record. It contains the following columns: VIAF_ID, Name_Type, Alternative_Names, Gender, Dates, Occupations, Countries, Unique_ISBNs, Titles, Sources, Coauthors, and Wikipedias.

Arguments

viaf

A list object containing the parsed JSON data from the VIAF API. This can be a single record's list or a list containing multiple parsed records.

check_dateType

Logical. If TRUE (default), applies special formatting to dates based on their dateType attribute (e.g., adding "ca." for circa dates, or converting "flourished" dates into centuries).

Details

This function relies on several internal auxiliary functions (e.g., v_titles, v_sources, v_wikipedias) to safely extract specific fields, bypassing empty strings or unexpected data structures often returned by the API.

Examples

Run this code
if (FALSE) {
# Assuming you have already downloaded and parsed a JSON response:
# library(jsonlite)
# parsed_data <- fromJSON("http://viaf.org/viaf/96136385/viaf.json")

# Convert the parsed list into a clean data frame
df_viaf <- v_dfVIAF(viaf = parsed_data, check_dateType = TRUE)
head(df_viaf)
}

Run the code above in your browser using DataLab