Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Update backslash handling
Browse files Browse the repository at this point in the history
  • Loading branch information
wch committed Aug 26, 2014
1 parent b2c8595 commit 1cb1672
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 16 deletions.
4 changes: 2 additions & 2 deletions R/utils_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ format_vec_d3json.POSIXt <- function(vec) floor(as.numeric(vec) * 1000)
format_vec_d3json.Date <- function(vec) as.numeric(as.POSIXct(vec)) * 1000


# Replace \ with \\, " with \", and add " to start and end
# Replace \. with . , " with \", and add " to start and end
quote_text <- function(txt) {
txt <- gsub("\\\\", "\\\\\\\\", txt, fixed = TRUE)
txt <- gsub("\\.", ".", txt, fixed = TRUE)
txt <- gsub('"', '\\\\"', txt, fixed = TRUE)
paste0('"', txt, '"')
}
Expand Down
6 changes: 0 additions & 6 deletions R/vega.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,6 @@ as.vega.data.frame <- function(x, name, ...) {
# Figure out correct vega parsers for non-string columns
parsers <- drop_nulls(lapply(x, vega_data_parser))

# Workaround for https://github.com/jeroenooms/jsonlite/issues/30 - need to
# double backslashes in names
if (!is.null(parsers)) {
names(parsers) <- gsub("\\", "\\\\", names(parsers), fixed = TRUE)
}

list(list(
name = name,
format = compact(list(
Expand Down
6 changes: 3 additions & 3 deletions tests/specs/data.r
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ library(ggvis)
library(dplyr, warn.conflicts = FALSE)

# Using "." in names of grouped and non-grouped vars
mtcars %>%
dplyr::mutate(cyl.new = factor(cyl), mpg.new = mpg) %>%
mtcars %>%
dplyr::mutate(cyl.new = factor(cyl), mpg.new = mpg) %>%
group_by(cyl.new) %>%
ggvis(~wt, ~mpg, fill = ~cyl.new) %>%
ggvis(~wt, ~mpg.new, fill = ~cyl.new) %>%
layer_points() %>%
save_spec("data/dots.json")
8 changes: 4 additions & 4 deletions tests/specs/data/dots.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"type" : "csv",
"parse" : {
"wt" : "number",
"mpg" : "number"
"mpg\\.new" : "number"
}
},
"values" : "\"cyl.new\",\"cyl\\.new\",\"wt\",\"mpg\"\n\"4\",\"4\",2.32,22.8\n\"4\",\"4\",3.19,24.4\n\"4\",\"4\",3.15,22.8\n\"4\",\"4\",2.2,32.4\n\"4\",\"4\",1.615,30.4\n\"4\",\"4\",1.835,33.9\n\"4\",\"4\",2.465,21.5\n\"4\",\"4\",1.935,27.3\n\"4\",\"4\",2.14,26\n\"4\",\"4\",1.513,30.4\n\"4\",\"4\",2.78,21.4\n\"6\",\"6\",2.62,21\n\"6\",\"6\",2.875,21\n\"6\",\"6\",3.215,21.4\n\"6\",\"6\",3.46,18.1\n\"6\",\"6\",3.44,19.2\n\"6\",\"6\",3.44,17.8\n\"6\",\"6\",2.77,19.7\n\"8\",\"8\",3.44,18.7\n\"8\",\"8\",3.57,14.3\n\"8\",\"8\",4.07,16.4\n\"8\",\"8\",3.73,17.3\n\"8\",\"8\",3.78,15.2\n\"8\",\"8\",5.25,10.4\n\"8\",\"8\",5.424,10.4\n\"8\",\"8\",5.345,14.7\n\"8\",\"8\",3.52,15.5\n\"8\",\"8\",3.435,15.2\n\"8\",\"8\",3.84,13.3\n\"8\",\"8\",3.845,19.2\n\"8\",\"8\",3.17,15.8\n\"8\",\"8\",3.57,15"
"values" : "\"cyl.new\",\"cyl.new\",\"wt\",\"mpg.new\"\n\"4\",\"4\",2.32,22.8\n\"4\",\"4\",3.19,24.4\n\"4\",\"4\",3.15,22.8\n\"4\",\"4\",2.2,32.4\n\"4\",\"4\",1.615,30.4\n\"4\",\"4\",1.835,33.9\n\"4\",\"4\",2.465,21.5\n\"4\",\"4\",1.935,27.3\n\"4\",\"4\",2.14,26\n\"4\",\"4\",1.513,30.4\n\"4\",\"4\",2.78,21.4\n\"6\",\"6\",2.62,21\n\"6\",\"6\",2.875,21\n\"6\",\"6\",3.215,21.4\n\"6\",\"6\",3.46,18.1\n\"6\",\"6\",3.44,19.2\n\"6\",\"6\",3.44,17.8\n\"6\",\"6\",2.77,19.7\n\"8\",\"8\",3.44,18.7\n\"8\",\"8\",3.57,14.3\n\"8\",\"8\",4.07,16.4\n\"8\",\"8\",3.73,17.3\n\"8\",\"8\",3.78,15.2\n\"8\",\"8\",5.25,10.4\n\"8\",\"8\",5.424,10.4\n\"8\",\"8\",5.345,14.7\n\"8\",\"8\",3.52,15.5\n\"8\",\"8\",3.435,15.2\n\"8\",\"8\",3.84,13.3\n\"8\",\"8\",3.845,19.2\n\"8\",\"8\",3.17,15.8\n\"8\",\"8\",3.57,15"
},
{
"name" : "mtcars %>% dplyr::mutate(cyl.new = factor(cyl), mpg.new = mpg) %>% group_by(cyl.new)0",
Expand Down Expand Up @@ -110,7 +110,7 @@
},
"y" : {
"scale" : "y",
"field" : "data.mpg"
"field" : "data.mpg\\.new"
}
},
"ggvis" : {
Expand Down Expand Up @@ -147,7 +147,7 @@
"orient" : "left",
"layer" : "back",
"grid" : true,
"title" : "mpg"
"title" : "mpg\\.new"
}
],
"ggvis_opts" : {
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/scatter/transform.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"format" : {
"type" : "csv",
"parse" : {
"x/y" : "number"
"x\/y" : "number"
}
},
"values" : "\"factor(x)\",\"x/y\"\n\"1\",0.2\n\"2\",0.5\n\"3\",1\n\"4\",2\n\"5\",5"
Expand Down

0 comments on commit 1cb1672

Please sign in to comment.