Creating JSON files for jsPSych experiments with R #1526
JAQuent
started this conversation in
Show and tell
Replies: 2 comments
-
This is very cool. Thanks for sharing! |
Beta Was this translation helpful? Give feedback.
0 replies
-
Just wanted to say thanks cos I simulate my trials in R as well and was tossing up between doing csv -> json -> js but I realise I can just do the json bit in R as well so thank you :) @JAQuent! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey,
I thought some might like this pipeline. What I like do for my jsPsych experiments, is to code all the trial information in R and hardcode that information into a .js file that I than load before the experiment.
For instance, I can take a data.frame in R like this one:
This particular function can be found here. This example .js file looks like this:
When I now run this
<script src="scene_repetition2_studyTask_trials.js"></script>
in the
<head></head>
part, then I can use variables a and b in my experiment. If I want I can use them as timeline variables. For that, I just create an array and use a simple for loop to assign the values to that array.then this arrary can be used like this
and then it has to be added to the timeline like this
If I have multiple counter balancing conditions, I use lists like this:
This creates a string like this
"var a = \"[[1,2],[4,5]]\";"
and I just have to write this one to .js file and add a = JSON.parse(a); and I can access the correct a for my particular condition by choosing a[0] vs. a[1].The function can be found here.
Note sure if that's the most elegant way to handle this kind of stuff but since I am more proficient in R prefer this and maybe it's helpful for someone else.
Beta Was this translation helpful? Give feedback.
All reactions