Skip to content

Commit f319a1b

Browse files
committed
fix: set unlimited number of digits when serializing an R decimal to JSON
1 parent 5592418 commit f319a1b

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

opal-r/src/main/java/org/obiba/opal/r/rserve/RserveConnection.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public RServerResult eval(String expr, RSerialize serialize) throws RServerExcep
7272
if (RSerialize.RAW == serialize) {
7373
cmd = String.format("try(serialize({%s}, NULL))", expr);
7474
} else if (RSerialize.JSON == serialize) {
75-
cmd = String.format("try(tryCatch(jsonlite::toJSON(%s, auto_unbox = T), error = function(e) { jsonlite::serializeJSON(%s) }))", expr, expr);
75+
cmd = String.format("try(tryCatch(jsonlite::toJSON(%s, auto_unbox = T, digits = NA), error = function(e) { jsonlite::serializeJSON(%s) }))", expr, expr);
7676
} else {
7777
cmd = String.format("try(%s)", expr);
7878
}

opal-r/src/main/resources/.execute.SQL.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.execute.SQL.JSON <- function(query, path = 'out.json') {
33
if (!require('sqldf')) { install.packages('sqldf', repos = "https://cloud.r-project.org") }
44
toJSON <- function(df) {
5-
jsonlite::toJSON(list(columns = names(df), rows = df), dataframe = 'values', na = 'null')
5+
jsonlite::toJSON(list(columns = names(df), rows = df), dataframe = 'values', na = 'null', digits = NA)
66
}
77
conn <- file(path)
88
writeLines(toJSON(sqldf::sqldf(query)), conn)

0 commit comments

Comments
 (0)