Create named list of options for parsing R from JSON
Usage
opts_read_json(
promote_num_to_string = FALSE,
digits_promote = 6,
df_missing_list_elem = NULL,
obj_of_arrs_to_df = TRUE,
arr_of_objs_to_df = TRUE,
arr_of_arrs_to_matrix = TRUE,
str_specials = c("string", "special"),
num_specials = c("special", "string"),
int64 = c("string", "double", "bit64"),
length1_array_asis = FALSE,
single_null = NULL,
empty_array = c("list", "NULL"),
empty_object = c("named_list", "NULL"),
yyjson_read_flag = 0L
)Arguments
- promote_num_to_string
Should numeric values be promoted to strings when they occur within an array with other string values? Default: FALSE means to keep numerics as numeric value and promote the container to be a
listrather than an atomic vector when types are mixed. IfTRUEthen array of mixed string/numeric types will be promoted to all string values and returned as an atomic character vector. Set this toTRUEif you want to emulate the behaviour ofjsonlite::fromJSON()- digits_promote
When promoting numbers to be strings, how many decimal places should be used in the representation. Default: 6. This option is only valid if
promote_num_to_string = TRUE. Valid range 0 to 30- df_missing_list_elem
R value to use when elements are missing in list columns in data.frames. Default: NULL
- obj_of_arrs_to_df
logical. Should a named list of equal-length vectors be promoted to a data.frame? Default: TRUE. If FALSE, then result will be left as a list.
- arr_of_objs_to_df
logical. Should an array of objects be promoted to a data.frame? Default: TRUE. If FALSE, then results will be read as a list-of-lists.
- arr_of_arrs_to_matrix
logical. Should an array of objects be promoted to a matrix (if types and dimensions align)? Default: TRUE. If FALSE, then results will be read as a list-of-atomic-vectors.
- str_specials
Should
'NA'in a JSON string be converted to the'special'NAvalue in R, or left as a'string'. Default: 'string'- num_specials
Should JSON strings 'NA'/'Inf'/'NaN' in a numeric context be converted to the
'special'R numeric valuesNA, Inf, NaN, or left as a'string'. Default: 'special'- int64
how to encode large integers which do not fit into R's integer type. 'string' imports them as a character vector. 'double' will convert the integer to a double precision numeric value. 'bit64' will use the 'integer64' type from the 'bit64' package. Note that the 'integer64' type is a signed integer type, and a warning will be issued if JSON contains an unsigned integer which cannot be stored in this type.
- length1_array_asis
logical. Should JSON arrays with length = 1 be marked with class
AsIs. Default: FALSE- single_null
R object to return for isolated JSON
nullvalues. Default: NULL. Note: JSONnullvalues in arrays may still be promoted toNAsof the appropriate type if possible.- empty_array
How should empty JSON arrays be returned? Default: 'list' for an empty list. Valid values: 'list', 'NULL'
- empty_object
How should empty JSON objects be returned? Default: 'named_list' for an empty named list. Valid values: 'named_list', 'NULL'
- yyjson_read_flag
integer vector of internal
yyjsonoptions. Seeyyjson_read_flagin this package, and read the yyjson API documentation for more information. This is considered an advanced option.
Examples
opts_read_json()
#> $promote_num_to_string
#> [1] FALSE
#>
#> $digits_promote
#> [1] 6
#>
#> $df_missing_list_elem
#> NULL
#>
#> $obj_of_arrs_to_df
#> [1] TRUE
#>
#> $arr_of_objs_to_df
#> [1] TRUE
#>
#> $arr_of_arrs_to_matrix
#> [1] TRUE
#>
#> $length1_array_asis
#> [1] FALSE
#>
#> $str_specials
#> [1] "string"
#>
#> $num_specials
#> [1] "special"
#>
#> $int64
#> [1] "string"
#>
#> $single_null
#> NULL
#>
#> $empty_array
#> [1] "list"
#>
#> $empty_object
#> [1] "named_list"
#>
#> $yyjson_read_flag
#> [1] 0
#>
#> attr(,"class")
#> [1] "opts_read_json"
