Learn R Programming

OAIHarvester (version 0.3-4)

serialize: Serialization for OAI-PMH Objects

Description

Functions to write a single OAI-PMH object to a file, and to restore it, and to perform the necessary conversions of XML objects to and from strings.

Usage

oaih_read_RDS(file, ...)
oaih_save_RDS(x, ...)
oaih_str_to_xml(x)
oaih_xml_to_str(x)

Arguments

x

an R object.

file

a connection or the name of the file where the R object is saved to.

...

arguments to be passed to readRDS (oaih_read_RDS) saveRDS (oaih_save_RDS).

Details

The OAI-PMH objects obtained by OAI-PMH requests (e.g., oaih_list_records) and subsequent transformations (oaih_transform) are made up of both character vectors and XML nodes from package xml2, with the latter lists of external pointers. Thus, serialization does not work “out of the box”, and in fact using refhooks in calls to readRDS or saveRDS does not work either (as one needs to (de)serialize a list of pointers, and not a single one). We thus provide helper functions to (recursively) (de)serialize the XML objects to/from strings, and to pre-process R objects before saving to a file and post-process after restoring from a file.

Examples

Run this code
tryCatch({
## Run inside tryCatch() so that checks fail gracefully if OAI-PMH
## requests time out or fail otherwise.
baseurl <- "https://research.wu.ac.at/ws/oai"
x <- oaih_identify(baseurl)
## Now 'x' is a list of character vectors and XML nodes:
x
## To save to a file and restore:
f <- tempfile()
oaih_save_RDS(x, file = f)
y <- oaih_read_RDS(f)
all.equal(x, y)
## Equivalently, we can directly pre-process before saving and
## post-process after restoring:
saveRDS(oaih_xml_to_str(x), f)
z <- oaih_str_to_xml(readRDS(f))
all.equal(y, z)
##
}, error = identity)

Run the code above in your browser using DataLab