diff --git a/NAMESPACE b/NAMESPACE index dbd228b..55880b5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,6 @@ exportPattern("^[^\\.]") import(plyr) -import(rjson) +import(RJSONIO) import(whisker) import(yaml) importFrom(lattice,latticeParseFormula) diff --git a/R/MorrisJS.R b/R/MorrisJS.R index 71d62a0..db7df8a 100644 --- a/R/MorrisJS.R +++ b/R/MorrisJS.R @@ -7,8 +7,8 @@ Morris = setRefClass('Morris', contains = 'rCharts', methods = list( }, getPayload = function(chartId){ params_ = fixLayerMorris(params) - chartParams = toJSON(params_[names(params_) != 'type']) - chartType = toJSON(params_$type) + chartParams = toJSON2(params_[names(params_) != 'type']) + chartType = toJSON2(params_$type) list(chartParams = chartParams, chartType = chartType) } )) diff --git a/R/toJSON.R b/R/toJSON.R index a943576..1f10435 100644 --- a/R/toJSON.R +++ b/R/toJSON.R @@ -24,7 +24,7 @@ toJSONArray <- function(obj, json = TRUE){ return(l) } if (json){ - rjson::toJSON(obj2list(obj)) + toJSON(obj2list(obj)) } else { obj2list(obj) } @@ -37,7 +37,7 @@ toJSONArray <- function(obj, json = TRUE){ #' @params name of object to apply the configuration to #' #' @keywords internal -#' @importFrom rjson toJSON +#' @importFrom RJSONIO toJSON #' @examples #' \dontrun{ #' toChain(list(showControls = TRUE, showDistX = TRUE), "chart") @@ -45,12 +45,8 @@ toJSONArray <- function(obj, json = TRUE){ #' } toChain <- function(x, obj){ config <- sapply(names(x), USE.NAMES = F, function(key){ - value = x[[key]] - if(grepl('^#!', value)){ - sprintf(" .%s(%s)", key, toObj(value)) - } else { - sprintf(" .%s(%s)", key, toJSON(value)) - } + value = toObj(toJSON(x[[key]], container = F, .escapeEscapes = F)) + sprintf(" .%s(%s)", key, value) }) if (length(config) != 0L){ paste(c(obj, config), collapse = '\n') @@ -59,7 +55,30 @@ toChain <- function(x, obj){ } } - toObj <- function(x){ - gsub('#!(.*)!#', "\\1", x) + gsub('\"#!(.*)!#\"', "\\1", x) +} + +toJSON2 <- function(x){ + toObj(toJSON(x, .escapeEscapes = F)) } + +# toObj <- function(x){ +# gsub('#!(.*)!#', "\\1", x) +# } + +# toChain <- function(x, obj){ +# config <- sapply(names(x), USE.NAMES = F, function(key){ +# value = x[[key]] +# if(any(grepl('^#!', value))){ +# sprintf(" .%s(%s)", key, toObj(value)) +# } else { +# sprintf(" .%s(%s)", key, toJSON(value)) +# } +# }) +# if (length(config) != 0L){ +# paste(c(obj, config), collapse = '\n') +# } else { +# "" +# } +# }