From d7fe11d56a2352e43d664958ee6060b23fd76771 Mon Sep 17 00:00:00 2001 From: Joe Cheng Date: Mon, 5 Jan 2015 11:30:01 -0800 Subject: [PATCH] Don't emit whitespace padding around numeric data Without this change, this is the behavior you get: ``` > RJSONIO::toJSON(head(cars, 3), digits = 12) [1] "{\n \"speed\": [ 4, 4, 7 ],\n\"dist\": [ 2, 10, 4 ] \n}" ``` With this change: ``` > RJSONIO::toJSON(head(cars, 3), digits = 12) [1] "{\n \"speed\": [ 4, 4, 7 ],\n\"dist\": [ 2, 10, 4 ] \n}" ``` The space savings are significant for many uses of Shiny and htmlwidgets. --- R/json.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/json.R b/R/json.R index f1e4035..0b073ad 100644 --- a/R/json.R +++ b/R/json.R @@ -169,7 +169,7 @@ setMethod("toJSON", "numeric", if(any(is.infinite(x))) warning("non-fininte values in numeric vector may not be approriately represented in JSON") - tmp = formatC(x, digits = digits) + tmp = formatC(x, digits = digits, width = 1) if(any(nas <- is.na(x))) tmp[nas] = .na