Permalink
Browse files

switch to RJSONIO and add toJSON2 support for MorrisJS

  • Loading branch information...
1 parent 8a4abf0 commit b7b3ce0b7b56ac405c94d17565bde0fe316e3fa2 @ramnathv committed Apr 26, 2013
Showing with 32 additions and 13 deletions.
  1. +1 −1 NAMESPACE
  2. +2 −2 R/MorrisJS.R
  3. +29 −10 R/toJSON.R
View
@@ -1,6 +1,6 @@
exportPattern("^[^\\.]")
import(plyr)
-import(rjson)
+import(RJSONIO)
import(whisker)
import(yaml)
importFrom(lattice,latticeParseFormula)
View
@@ -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)
}
))
View
@@ -24,7 +24,7 @@ toJSONArray <- function(obj, json = TRUE){
return(l)
}
if (json){
- rjson::toJSON(obj2list(obj))
+ toJSON(obj2list(obj))
} else {
obj2list(obj)
}
@@ -37,20 +37,16 @@ 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")
#' ## chart.showControls(true).showDistX(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 {
+# ""
+# }
+# }

0 comments on commit b7b3ce0

Please sign in to comment.