Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/asJSON.Date.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
setMethod("asJSON", "Date", function(x, Date = c("ISO8601", "epoch"), always_decimal = FALSE, ...) {
# Validate argument
Date <- match.arg(Date)
Date <- match.arg(Date, c("ISO8601", "epoch"))

# select a schema
output <- switch(
Expand Down
2 changes: 1 addition & 1 deletion R/asJSON.POSIXt.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ setMethod("asJSON", "POSIXt", function(x, POSIXt = c("string", "ISO8601", "epoch
# instead of ?as.character

# Validate
POSIXt <- match.arg(POSIXt)
POSIXt <- match.arg(POSIXt, c("string", "ISO8601", "epoch", "mongo"))

# Encode based on a schema
if (POSIXt == "mongo") {
Expand Down
2 changes: 1 addition & 1 deletion R/asJSON.array.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
asjson_array_fun <- function(x, collapse = TRUE, na = NULL, oldna = NULL, matrix = c("rowmajor", "columnmajor"), auto_unbox = FALSE, keep_vec_names = FALSE, indent = NA_integer_, ...) {
matrix <- match.arg(matrix)
matrix <- match.arg(matrix, c("rowmajor", "columnmajor"))

# reset na arg when called from data frame
if (identical(na, "NA")) {
Expand Down
2 changes: 1 addition & 1 deletion R/asJSON.character.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ setMethod("asJSON", "character", function(x, collapse = TRUE, na = c("null", "st

# validate NA
if (any(missings <- which(is.na(x)))) {
na <- match.arg(na)
na <- match.arg(na, c("null", "string", "NA"))
if (na %in% c("null")) {
tmp[missings] <- "null"
} else if (na %in% "string") {
Expand Down
4 changes: 2 additions & 2 deletions R/asJSON.complex.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
setMethod("asJSON", "complex", function(x, digits = 5, collapse = TRUE, complex = c("string", "list"), na = c("string", "null", "NA"), oldna = NULL, ...) {
# validate
na <- match.arg(na)
complex <- match.arg(complex)
na <- match.arg(na, c("string", "null", "NA"))
complex <- match.arg(complex, c("string", "list"))

#turn into strings
if (complex == "string") {
Expand Down
4 changes: 2 additions & 2 deletions R/asJSON.data.frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ setMethod("asJSON", "data.frame", function(x, na = c("NA", "null", "string"), co
}

# Validate some args
dataframe <- match.arg(dataframe)
dataframe <- match.arg(dataframe, c("rows", "columns", "values"))
has_names <- identical(length(names(x)), ncol(x))

# Default to adding row names only if they are strings and not just stringified numbers
Expand Down Expand Up @@ -43,7 +43,7 @@ setMethod("asJSON", "data.frame", function(x, na = c("NA", "null", "string"), co

# Set default for row based, don't do it earlier because it will affect 'oldna' or dataframe="columns"
if (dataframe == "rows" && has_names) {
na <- match.arg(na)
na <- match.arg(na, c("NA", "null", "string"))
}

# no records
Expand Down
2 changes: 1 addition & 1 deletion R/asJSON.difftime.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ setMethod("asJSON", "ts", function(x, ...) {
})

setMethod("asJSON", "hms", function(x, hms = c("string", "secs"), ...) {
hms <- match.arg(hms)
hms <- match.arg(hms, c("string", "secs"))
output <- switch(hms, string = as.character(x), secs = as.numeric(x, units = "secs"))
output[is.na(x)] <- NA
asJSON(output, ...)
Expand Down
2 changes: 1 addition & 1 deletion R/asJSON.factor.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
setMethod("asJSON", "factor", function(x, factor = c("string", "integer"), keep_vec_names = FALSE, ...) {
# validate
factor <- match.arg(factor)
factor <- match.arg(factor, c("string", "integer"))

# dispatch
if (factor == "integer") {
Expand Down
2 changes: 1 addition & 1 deletion R/asJSON.function.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
setMethod("asJSON", "function", function(x, collapse = TRUE, fun = c("source", "list"), ...) {
# validate
fun <- match.arg(fun)
fun <- match.arg(fun, c("source", "list"))

if (fun == "source") {
return(asJSON(deparse(x), ...))
Expand Down
2 changes: 1 addition & 1 deletion R/asJSON.logical.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ setMethod("asJSON", "logical", function(x, collapse = TRUE, na = c("null", "stri
}

# validate arg
na <- match.arg(na)
na <- match.arg(na, c("null", "string", "NA"))

# json true/false
tmp <- ifelse(x, "true", "false")
Expand Down
2 changes: 1 addition & 1 deletion R/asJSON.numeric.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ asjson_numeric_fun <- function(x, digits = 5, use_signif = is(digits, "AsIs"), n
return(asJSON(as.list(x), digits = digits, use_signif = use_signif, na = na, auto_unbox = TRUE, collapse = collapse, ...))
}

na <- match.arg(na)
na <- match.arg(na, c("string", "null", "NA"))
na_as_string <- switch(na, "string" = TRUE, "null" = FALSE, "NA" = NA, stop("invalid na_as_string"))

# old R implementation
Expand Down
2 changes: 1 addition & 1 deletion R/asJSON.raw.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ setMethod("asJSON", "blob", function(x, raw = "base64", ...) {

setMethod("asJSON", "raw", function(x, raw = c("base64", "hex", "mongo", "int", "js"), ...) {
# validate
raw <- match.arg(raw)
raw <- match.arg(raw, c("base64", "hex", "mongo", "int", "js"))

# encode based on schema
if (raw == "mongo") {
Expand Down
2 changes: 1 addition & 1 deletion R/asJSON.sf.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# For 'sf' geometry columns; use same structure as GeoJSON
setMethod("asJSON", "sf", function(x, sf = c("dataframe", "features", "geojson"), ...) {
sf <- match.arg(sf)
sf <- match.arg(sf, c("dataframe", "features", "geojson"))
if (sf == 'dataframe') {
callNextMethod()
} else {
Expand Down
18 changes: 9 additions & 9 deletions R/toJSON.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ toJSON <- function(
...
) {
# validate args
dataframe <- match.arg(dataframe)
matrix <- match.arg(matrix)
Date <- match.arg(Date)
POSIXt <- match.arg(POSIXt)
factor <- match.arg(factor)
complex <- match.arg(complex)
raw <- match.arg(raw)
null <- match.arg(null)
dataframe <- match.arg(dataframe, c("rows", "columns", "values"))
matrix <- match.arg(matrix, c("rowmajor", "columnmajor"))
Date <- match.arg(Date, c("ISO8601", "epoch"))
POSIXt <- match.arg(POSIXt, c("string", "ISO8601", "epoch", "mongo"))
factor <- match.arg(factor, c("string", "integer"))
complex <- match.arg(complex, c("string", "list"))
raw <- match.arg(raw, c("base64", "hex", "mongo", "int", "js"))
null <- match.arg(null, c("list", "null"))

# Temp workaround for 'mongopipe' unit test
# if (pretty == 2 && identical(x, list()) && identical(Sys.getenv('TESTTHAT_PKG'), 'mongopipe')) {
Expand All @@ -36,7 +36,7 @@ toJSON <- function(

#this is just to check, we keep method-specific defaults
if (!missing(na)) {
na <- match.arg(na)
na <- match.arg(na, c("null", "string"))
} else {
na <- NULL
}
Expand Down
Loading