mhtess / rwebppl

RWebPPL, an R interface to Webppl http://webppl.org
22 stars 7 forks source link

Don't serialize single values passed in as data #24

Closed mhtess closed 8 years ago

mhtess commented 8 years ago

When passing data, a la:

posterior <- webppl(
  program_code = model,
  model_var = "model",
  data_var = "data_from_R",
  data = list(number_heads = 15, number_flips = 20)
)
model <- "
var number_heads = data_from_R.number_heads
var number_flips = data_from_R.number_flips
number_heads
"

will return [15]. This is annoying when you are assuming that it will be a single number. It would be good (if possible) to not run toJSON on single values so that number_heads will return 15.

mhtess commented 8 years ago

On second thought, this is pretty silly

mhtess commented 8 years ago

For reference:

> toJSON(list(a = 5, b= 3))
{"a":[5],"b":[3]} 
> toJSON(data.frame(a = 5, b = 3))
[{"a":5,"b":3}]