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. In addition, this function allows you to save to various places, including Rds files, cached via R.cache, or to Redis.

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, 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 read_xml or 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
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
## Not run: 
dois <- c('10.1371/journal.pone.0087376','10.1371%2Fjournal.pone.0086169',
'10.1371/journal.pone.0102976','10.1371/journal.pone.0105225',
'10.1371/journal.pone.0102722','10.1371/journal.pone.0033693')
res <- ft_get(dois, from='plos')

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

# From XML to JSON
(out <- ft_serialize(res, to='json'))
out$plos$data$data$`10.1371/journal.pone.0087376` # the json
jsonlite::fromJSON(out$plos$data$data$`10.1371/journal.pone.0087376`)

# To a list
out <- ft_serialize(res, to='list')
out$plos$data$data[[4]]
out$plos$data$data[[4]][[2]]$`article-meta`

# To various data stores on disk
## To an .Rds file
ft_serialize(res, to='file')

## To local files using R.cache package
res_rcache <- ft_serialize(res, to='rcache')

## To Redis
res_redis <- ft_serialize(res, to='redis')

# Chain together functions
doi <- '10.1371/journal.pone.0086169'
ft_get(doi, from='plos') %>%
   ft_serialize(to='xml') %>%
   ft_serialize(to='redis')

## End(Not run)