mhtess / rwebppl

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

Pass data from R to WebPPL #1

Closed mhtess closed 8 years ago

mhtess commented 8 years ago

If you have a data frame df that might look like

Participant Condition Response
1 A 0.4
1 B 0.8
2 A 0.2

You could convert it into a list of js objects e.g.

[
{
  participant: 0,
  condition: "A",
  response: 0.4
},
{
  participant: 0,
  condition: "B",
  response: 0.8
},
{
  participant: 1,
  condition: "A",
  response: 0.2
}, 
...
]

And use jsonlite to serialize it. You could prepend the webppl model with something like "var data = " + jsonlite::toJSON(df)