library(jaysire)
set.seed(143)

In this example we’ll build a relatively simple choice reaction time experiment. On any given trial, the participant will be presented with a blue circle or an orange circle, and will respond by pressing the “F” or “J” keys. It is almost identical to the demonstration experiment used in the jsPsych documentation.

Creating the resource files

library(ggplot2)

# where should the images be stored initially?
resources <- temporary_folder()  
blue_image <- file.path(resources, "blue.png")
orange_image <- file.path(resources, "orange.png")

# create the blue circle plot
blue_pic <- ggplot() + theme_void() +
  annotate(geom = "point", x = 0, y = 0, colour = "blue", size = 60)

# create the orange circle plot
orange_pic <- ggplot() + theme_void() +
  annotate(geom = "point", x = 0, y = 0, colour = "orange", size = 60)

# save the images to files in the resource folder
ggsave(filename = blue_image, plot = blue_pic, width = 2, height = 2)
ggsave(filename = orange_image, plot = orange_pic, width = 2, height = 2)

# check that it worked
list.files(resources)
#> [1] "blue.png"   "orange.png"

Building the experiment

Working version of the experiment here.