The trial_generic
function is used to create a trial with
an arbitrary jsPsych plugin.
trial_generic(type, ...)
type | the type of trial |
---|---|
... | arguments passed to the trial plugin |
Functions with a trial_
prefix always return a "trial" object.
A trial object is simply a list containing the input arguments, with
NULL
elements removed. Logical values in the input (TRUE
and
FALSE
) are transformed to character vectors "true"
and "false"
and are specified to be objects of class "json", ensuring that they will be
written to file as the javascript logicals, true
and false
.
The trial_generic()
function is the most flexible of
all the functions within the trial_
family, and can be use to
insert a trial of any type
. For example, by setting
type = "image-keyboard-response"
, it will create an image trial
using a keyboard response, precisely analogous to trials created using
the trial_image_keyboard_response()
function. More generally
the type
value should be a string that specifies the name of the
corresponding jsPsych plugin file: in this case, the file name for the
plugin "jspsych-image-keyboard-response.js" so the corresponding type
value is "image-keyboard-response".
While the advantage to trial_generic()
is flexibility, the disadvantage
is that all arguments to the plugin must be specified as named arguments passed
via ...
, and it can take some trial and error to get a novel plugin to
behave in the expected fashion. For example, if a particular argument to the
jsPsych plugin takes a logical value, it may not always be sufficient to
use logical values TRUE
or FALSE
when the trial is constructed
from within R. The reason for this is that when the R code is converted to
javascript (using the jsonlite package), it does correctly convert
the R logicals TRUE
and FALSE
to the corresponding javascript
logical values true
and false
, but by default this value is
written to a javascript array of length one rather than recorded as a scalar
value (i.e., the javascript code becomes [true]
rather than true
).
When this occurs, jsPsych often does not produce the desired behaviour as
these two entities are not considered equivalent in javascript.
In future versions of jaysire there may be better support for arbitary
plugins, but for the moment users should be aware that trial_generic()
can be somewhat finicky to work with.