cereal_encode {cereal} | R Documentation |
Encode a vector as JSON
Description
Create a list encoding the vctrs prototype (metadata) that can be stored as JSON.
Usage
cereal_encode(x)
Arguments
x |
A vector |
Details
Use the digits
option to specify how many digits after the decimal point
to record in JSON, for example via withr::local_options()
.
Value
A list that can be converted to JSON with jsonlite::toJSON()
See Also
vctrs::vec_ptype()
, cereal_decode()
Examples
cereal_encode(1:10)
cereal_encode(Sys.Date())
cereal_encode(sample(letters, 5))
cereal_encode(factor(letters[1:5], labels = "letter"))
cereal_encode(factor(LETTERS[3:1], ordered = TRUE))
## you can encode a ptype as well:
ptype <- vctrs::vec_ptype(factor(LETTERS[3:1], ordered = TRUE))
## but "example" is NULL:
cereal_encode(ptype)
[Package cereal version 0.1.0 Index]