Skip to content

Commit

Permalink
switch to RJSONIO and add toJSON2 support for MorrisJS
Browse files Browse the repository at this point in the history
  • Loading branch information
ramnathv committed Apr 26, 2013
1 parent 8a4abf0 commit b7b3ce0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
exportPattern("^[^\\.]")
import(plyr)
import(rjson)
import(RJSONIO)
import(whisker)
import(yaml)
importFrom(lattice,latticeParseFormula)
Expand Down
4 changes: 2 additions & 2 deletions R/MorrisJS.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
))
Expand Down
39 changes: 29 additions & 10 deletions R/toJSON.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ toJSONArray <- function(obj, json = TRUE){
return(l)
}
if (json){
rjson::toJSON(obj2list(obj))
toJSON(obj2list(obj))
} else {
obj2list(obj)
}
Expand All @@ -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')
Expand All @@ -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.