From f61a2541f9f1e239f8bdc92f68c269c5f3a3cec1 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 20 Mar 2015 14:27:24 +0100 Subject: [PATCH] Remove newline characters from JSON In some cases (did not figure out when and when not), toJSON leads to representations like > toJSON(x_2) [1] "[ [\n \"Scenario\",\n\"Waterbody\", .... instead of > toJSON(x_1) [1] "[ [ \"Scenario\", \"Waterbody\", ... which makes python.assign fail with the message SyntaxError: EOL while scanning string literal This can be avoided by substituting the newline characters in the JSON string before it is passed to the Python interpreter. --- R/python.assign.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/python.assign.R b/R/python.assign.R index 115f9ed..7e19551 100644 --- a/R/python.assign.R +++ b/R/python.assign.R @@ -6,6 +6,9 @@ python.assign <- function( var.name, value ){ #value <- toJSON( value ) value <- toJSON( value, collapse = "" ) + + # Sometimes toJSON introduces newlines that disturb the python interpreter + value <- gsub("\n", "", value) # Creating the call