djnavarro / xprmntr

Build browser-based behavioural experiments in R

Home Page:https://djnavarro.github.io/xprmntr/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

I think I broke the demo

Maschette opened this issue · comments

It is super likely it is just me doing something wrong.

library(xprmntr)



# welcome trial -----------------------------------------------------------

welcome_trial <- trial_simple(
    cue = cue_html("Welcome to the experiment! Press any key to continue"),
    response = response_key("any")
)




# choice trials -----------------------------------------------------------

# define a fixation trial
fixation <- trial_simple(
    cue = cue_html('<div style="font-size:60px;">+</div>'),
    response = response_key("none"),
    trial_duration = 500
)

# define a test trial
query <- trial_simple(
    cue = cue_image(stimulus = variable("stimulus")),
    response = response_key("y", "n"),
    prompt = variable("prompt")
)

# define stimuli
flag_names <- c("bisexual", "transgender", "LGBT")
flag_files <- c("bisexual.svg", "transgender.svg", "rainbow.svg")

# testing procedure is a timeline of fixate/query events
choice_trials <- timeline(fixation, query) %>%
    with_variables(
        prompt = paste("is this the", flag_names, "flag? (y/n)"),
        stimulus = resource(flag_files)) %>%
    with_parameters(randomize_order = TRUE, repetitions = 2)



# likert survey -----------------------------------------------------------

# define some response scale
confidence <- c("very unsure", "somewhat unsure", "somewhat sure", "very sure")
boredom <- c("not at all bored", "somewhat bored", "very bored")

# define a survey question
likert_confidence <- question(
    cue = cue_text("How confident were you in your answers?"),
    response = response_likert(labels = confidence),
    required = TRUE
)

# define a survey question
likert_bored <- question(
    cue = cue_text("How bored were you in your answers?"),
    response = response_likert(labels = boredom),
    required = FALSE
)

# compose a likert survey
survey_likert <- trial_survey(
    questions = list(likert_confidence, likert_bored),
    preamble = "We have some questions"
)



# pick one survey ---------------------------------------------------------

# define a survey question
pickone_gender <- question(
    cue = cue_text("What gender are you?"),
    response = response_pickone(
        options = c("male", "female", "non-binary", "other")
    ),
    required = FALSE
)

# define a survey question
pickone_identity <- question(
    cue = cue_text("Do you identify as LGBTIQ?"),
    response = response_pickone(
        options = c("yes", "no", "maybe")
    ),
    required = FALSE
)

# define a multiple choice survey page
survey_pickone <- trial_survey(
    questions = list(pickone_gender, pickone_identity),
    preamble = "We have some more questions"
)



# pick some survey -----------------`---------------------------------------


# define a survey question
picksome_identities <- question(
    cue = cue_text("Select all that apply"),
    response = response_picksome(
        options = c("lesbian", "gay", "bisexual", "transgender",
                                "intersex", "queer", "other")
    ),
    required = FALSE
)

# define a multi select page
survey_picksome <- trial_survey(picksome_identities)



# free text survey --------------------------------------------------------



# define a free text page
survey_freetext <- question(
    cue_text("Anything to add?"),
    response_freetext()
) %>%
    trial_survey()



# finish trial ------------------------------------------------------------

finish_trial <- trial_simple(
    cue_html("All done!"),
    response_key("any")
)




# organise into a structure -----------------------------------------------

all_events <- timeline(
    welcome_trial,
    choice_trials,
    survey_likert,
    survey_pickone,
    survey_picksome,
    survey_freetext,
    finish_trial
)




# write the experiment files ----------------------------------------------

resources <- add_resources(
    system.file("extdata", "img", package = "xprmntr")
)

experiment(
    timeline = all_events,
    path = "~/Desktop/expt",
    resources = resources,
    default_iti = 250,
    on_finish = js_code("xprmntr.save_locally"),
    preload_images = resource(flag_files)
)
#> Warning in dir.create(path): cannot create dir 'C:
#> \Users\dale_mas\Documents\Desktop\expt', reason 'No such file or directory'
#> Warning in dir.create(file.path(path, "experiment")): cannot create dir 'C:
#> \Users\dale_mas\Documents\Desktop\expt\experiment', reason 'No such file or
#> directory'
#> Warning in dir.create(file.path(path, "experiment", "resource")): cannot create
#> dir 'C:\Users\dale_mas\Documents\Desktop\expt\experiment\resource', reason 'No
#> such file or directory'
#> Warning in dir.create(file.path(path, "experiment",
#> "resource", "script")): cannot create dir 'C:
#> \Users\dale_mas\Documents\Desktop\expt\experiment\resource\script', reason 'No
#> such file or directory'
#> Warning in dir.create(file.path(path, "experiment",
#> "resource", "style")): cannot create dir 'C:
#> \Users\dale_mas\Documents\Desktop\expt\experiment\resource\style', reason 'No
#> such file or directory'
#> Warning in dir.create(file.path(path, "experiment",
#> "resource", "audio")): cannot create dir 'C:
#> \Users\dale_mas\Documents\Desktop\expt\experiment\resource\audio', reason 'No
#> such file or directory'
#> Warning in dir.create(file.path(path, "experiment",
#> "resource", "video")): cannot create dir 'C:
#> \Users\dale_mas\Documents\Desktop\expt\experiment\resource\video', reason 'No
#> such file or directory'
#> Warning in dir.create(file.path(path, "experiment",
#> "resource", "image")): cannot create dir 'C:
#> \Users\dale_mas\Documents\Desktop\expt\experiment\resource\image', reason 'No
#> such file or directory'
#> Warning in dir.create(file.path(path, "experiment",
#> "resource", "other")): cannot create dir 'C:
#> \Users\dale_mas\Documents\Desktop\expt\experiment\resource\other', reason 'No
#> such file or directory'
#> Warning in dir.create(file.path(path, "data")): cannot create dir 'C:
#> \Users\dale_mas\Documents\Desktop\expt\data', reason 'No such file or directory'
#> Warning in file.create(to[okay]): cannot create file '~/Desktop/expt/experiment/
#> resource/image/bisexual.png', reason 'No such file or directory'
#> Warning in file.create(to[okay]): cannot create file '~/Desktop/expt/experiment/
#> resource/image/bisexual.svg', reason 'No such file or directory'
#> Warning in file.create(to[okay]): cannot create file '~/Desktop/expt/experiment/
#> resource/image/lesbian.svg', reason 'No such file or directory'
#> Warning in file.create(to[okay]): cannot create file '~/Desktop/expt/experiment/
#> resource/image/rainbow.svg', reason 'No such file or directory'
#> Warning in file.create(to[okay]): cannot create file '~/Desktop/expt/experiment/
#> resource/image/transgender.svg', reason 'No such file or directory'
#> Warning in file.create(to[okay]): cannot create file '~/Desktop/expt/experiment/
#> resource/style', reason 'No such file or directory'
#> Error in file.copy(from = system.file("extdata", "jsPsych-6.1.0", scripts, : more 'from' files than 'to' files

sessionInfo()
#> R version 3.6.1 (2019-07-05)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 17134)
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252   
#> [3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                      
#> [5] LC_TIME=English_Australia.1252    
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] xprmntr_0.0.0.9000
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.2       crayon_1.3.4     digest_0.6.21    magrittr_1.5    
#>  [5] evaluate_0.14    pillar_1.4.2     highr_0.8        rlang_0.4.0     
#>  [9] stringi_1.4.3    rmarkdown_1.15.2 tools_3.6.1      stringr_1.4.0   
#> [13] purrr_0.3.2      xfun_0.9         yaml_2.2.0       compiler_3.6.1  
#> [17] pkgconfig_2.0.3  htmltools_0.3.6  knitr_1.25.1     tibble_2.1.3

Created on 2019-10-09 by the reprex package (v0.3.0)

ok the issue was the "~/Desktop/expt" it won't create a folder and a subfolder if I remove the Desktop and just use "~/expt" it works fine.

it does however fall over if that folder already exists.