How do I pass raw JSON strings to the DeployR WebAPI?

134 Views Asked by At

Scenario:

I have a set of inputs that I need to pass through to the deployr server. Certain parameters are simple strings but others are JSON strings that get converted by the R script by calling fromJSON.

Problem

When I pass the simple string values to the server they are fine but when I try pass a JSON formatted string to the server, the script execution fails. This script has been tested locally and using it via the R.Net library also works. Unfortunately R.Net does not suite our use case as we need multi threading.

Example:

var jsonString = RDataFactory.createString("jsonData",
File.ReadAllText("Data/jsonData.txt"));

taskOptions.rinputs.Add(jsonString);

//Execute request ....

Where the JSON data looks like this

//jsonData.txt
{"ID":77674,"Name":"My Company","CurrencySymbol":"R"}

And the R call failing is

deployrInput('{ "name": "jsonData", "default": "", "render": "character" } ')
mydata <- fromJSON(jsonData) #everything disintegrates

Question:

How do I pass a raw string that is JSON formatted as an rinput to the deployr server?

Please forgive me if it is something small, relatively new to all this and couldn't find anything helpful in the docs.

Thanks in advance!

1

There are 1 best solutions below

0
RabidDog5150 On

Figured it out. Seems the "rjson" package doesn't play nicely with DeployR.

Using the package "jsonlite" resolved the issue.