Learn R Programming

fulltext (version 2.0)

ft_serialize: Serialize raw text to other formats, including to disk

Description

ft_serialize helps you convert to various data formats. If your data is in unparsed XML (i.e., character class), you can convert to parsed XML. If in XML, you can convert to (ugly-ish) JSON, or a list.

Usage

ft_serialize(x, to = "xml", from = NULL, ...)

ft_get_keys(x)

Arguments

x

Input object, output from a call to ft_get. Required.

to

(character) Format to serialize to. One of list, xml, or json. Required. Output to xml returns object of class XMLInternalDocument.

from

(character) Format x is currently in. Function attempts to use metadata provided, or guess from data itself. Optional. CURRENTLY IGNORED.

...

Further args passed on to xml2::read_xml() or jsonlite::toJSON()

Value

An object of class ft_parsed

Examples

Run this code
# NOT RUN {
res <- ft_get('10.7717/peerj.228')

# if articles in xml format, parse the XML
(out <- ft_serialize(ft_collect(res), to='xml'))
out$peerj$data$data[[1]] # the xml

# From XML to JSON
(out <- ft_serialize(ft_collect(res), to='json'))
out$peerj$data$data$`10.7717/peerj.228` # the json
jsonlite::fromJSON(out$peerj$data$data$`10.7717/peerj.228`)

# To a list
out <- ft_serialize(ft_collect(res), to='list')
out$peerj$data$data
out$peerj$data$data[[1]]$body$sec$title
# }

Run the code above in your browser using DataLab