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

Description Usage Arguments Value Examples

View source: R/ft_serialize.R

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

1
2
3
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## 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

## End(Not run)

fulltext documentation built on Feb. 9, 2018, 6:08 a.m.