R/encode.R
raw| 1 | encode <- function(...) { |
| 2 | data <- dots_list(..., .homonyms = "error", .check_assign = TRUE) |
| 3 | |
| 4 | if (!is_named(data)) { |
| 5 | vars <- enexprs(...) |
| 6 | unnamed <- vars[!have_name(vars)] |
| 7 | |
| 8 | cli::cli_abort(c( |
| 9 | "All data variables must be named.", |
| 10 | "x" = "Unnamed variables: {.var {unnamed}}" |
| 11 | )) |
| 12 | } |
| 13 | |
| 14 | jsonlite::toJSON( |
| 15 | data, |
| 16 | auto_unbox = TRUE, # length-1 vectors output as scalars |
| 17 | no_dots = TRUE # dots reserved by template syntax |
| 18 | ) |
| 19 | } |