insert_variable: Insert reference to a timeline variable

Description Usage Arguments Details Value See Also Examples

View source: R/insert.R

Description

Insert reference to a timeline variable

Usage

1

Arguments

name

String specifying name of the variable to insert

Details

When creating an experiment, a common pattern is to create a series of trials that are identical in every respect except for one thing that varies across the trial (e.g., a collection of trial_html_button_response() trials that are the same except for the text that is displayed). A natural way to handle this in the jsPsych framework is to create the trial in the usual fashion, except that instead of specifying the value that needs to be included in the trial (e.g., the text itself) the code includes a reference to a timeline variable. This is the job of the insert_resource() function. As an example, instead of creating a trial in which stimulus = "cat" and another one that is identical except that stimulus = "dog", you could create a "template" for both trials by setting stimulus = insert_variable("animal"). This acts as a kind promise that is filled (at runtime) by looking for an "animal" variable attached to the timeline. See the examples section for an illustration of how these functions are intended to work together.

Value

Javascript code that calls the jsPsych.timelineVariable() function

See Also

set_variables(), build_timeline()

Examples

1
2
3
4
5
6
7
# create a template from which a series of trials can be built
template <- trial_html_button_response(stimulus = insert_variable("animal"))

# create a timeline with three trials, all using the same template
# but with a different value for the "animal" variable
timeline <- build_timeline(template) %>%
  set_variables(animal = c("cat", "dog", "pig"))

djnavarro/jaysire documentation built on April 12, 2021, 4:25 a.m.