-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscriptR.r
2088 lines (1783 loc) · 109 KB
/
scriptR.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# scriptR for Eyetrack experiments by Michael Wilson####
# Libraries ####
# Checks if the required packages are installed, and installs them if not
# Code from https://stackoverflow.com/questions/9341635/check-for-installed-packages-before-running-install-packages, user Sean Murphy
packages <- c("dplyr", "data.table", "gplots", "stringr", "tidyr", "plotrix")
if (length(setdiff(packages, rownames(installed.packages()))) > 0) {
install.packages(setdiff(packages, rownames(installed.packages())))
}
suppressMessages(library(dplyr)) # Several functions
suppressMessages(library(data.table)) # For %like% operator
suppressMessages(library(gplots)) # For col2hex
suppressMessages(library(stringr)) # For str_locate
suppressMessages(library(tidyr)) # For spread
suppressMessages(library(plotrix)) # For color.id()
# Get directory function ####
# From https://stackoverflow.com/questions/49196697/how-to-get-the-directory-of-the-executing-script-in-r, user "tinker"
get_directory <- function() {
args <- commandArgs(trailingOnly = FALSE)
file <- "--file="
match <- grep(file, args)
if (length(match) > 0) {
return(dirname(normalizePath(sub(file, "", args[match]))))
} else {
return(dirname(normalizePath(sys.frames()[[1]]$ofile)))
}
}
# Prompt for user parameters ####
{
# Read in the stimuli file ####
cat("Enter stimuli CSV location: ")
filepath <- readLines("stdin", n = 1)
if(!(filepath %like% "\\.csv$")){
filepath <- paste(filepath, ".csv", sep = "")
}
while(!file.exists(filepath)){
cat("No CSV file found at that location. Please enter a valid location: ")
filepath <- readLines("stdin", n = 1)
if(!(filepath %like% "\\.csv$")){
filepath <- paste(filepath, ".csv", sep = "")
}
}
filename <- sub(".*(\\/|\\\\)", "", filepath) %>% sub("\\.csv", "", .)
filepath <- sub(paste(sep = "", filename, ".csv"), "", filepath)
stimuli <- read.csv(paste(filepath, filename, ".csv", sep = ""))
# Clean the stimuli file ####
{
# Warn if item_condition is already specified ####
if(!((is.null(stimuli$item_condition)) | all(is.na(stimuli$item_condition)) | all(stimuli$item_condition == ""))){
cat("Warning: item_condition already specified in stimuli CSV, and will be overwritten.\n")
stimuli <- stimuli %>% dplyr::select(-item_condition) %>% droplevels()
}
# If some item number is not specified, exit ####
if(is.null(stimuli$item_id) | any(is.na(stimuli$item_id)) | any(stimuli$item_id == "") | !all(stimuli$item_id %like% "^Message$|^[1-9][0-9]*$")){
cat("Error: item numbers not properly specified. ")
.Internal(.invokeRestart(list(NULL, NULL), NULL))
}
# If some experiment is not specified correctly, attempt to get practice items automatically ####
if(is.null(stimuli$Experiment) | any(is.na(stimuli$Experiment)) | any(stimuli$Experiment == "") | !all(stimuli$Experiment %like% "^P$|^[1-9][0-9]*$")){
stimuli$Experiment <- ""
# Find the first and last Message items, if they exist, and assume they delimit the practice items
for(i in 1:nrow(stimuli)){
if(stimuli[i,]$item_id == "Message"){
if(!exists("first.practice.row")){
first.practice.row <- i
} else {
last.practice.row <- i
}
}
}
# If there's only one practice row, set the value of last practice row equal to the value of first practice row
if(!exists("last.practice.row")){
if(exists("first.practice.row")){
last.practice.row <- first.practice.row
}
}
# If there are practice items, set the experiment value for those to P
if(exists("first.practice.row")) {
stimuli[c(first.practice.row:last.practice.row),]$Experiment <- "P"
}
}
# Temporarily discard any practice items ####
practice <- stimuli %>% filter(Experiment == "P") %>% droplevels()
stimuli <- stimuli %>% filter(Experiment != "P") %>% transform(Experiment = as.factor(Experiment)) %>% droplevels()
rownames(stimuli) <- c(1:nrow(stimuli))
# Practice defaults ####
if(nrow(practice) > 0){
# Specify a dummy item_condition for practice items
practice$item_condition <- "1"
# Set any non Message practice items to item 1
practice$item_id <- ifelse(practice$item_id == "Message", "Message", "1")
if(is.null(practice$Timeout)){
practice$Timeout <- "30000"
} else if(any(is.na(practice$Timeout)) | any(practice$Timeout == "") | !all(practice$Timeout %like% "^[1-9][0-9]*$")) {
practice$Timeout <- as.character(practice$Timeout)
practice[is.na(practice$Timeout) | practice$Timeout == "" | !(practice$Timeout %like% "^[1-9][0-9]*$"), ]$Timeout <- "30000"
}
if(is.null(practice$QTimeout)){
practice$QTimeout <- "30000"
} else if(any(is.na(practice$QTimeout)) | any(practice$QTimeout == "") | !all(practice$QTimeout %like% "^[1-9][0-9]*$")) {
practice$QTimeout <- as.character(practice$QTimeout)
practice[is.na(practice$QTimeout) | practice$QTimeout == "" | !(practice$QTimeout %like% "^[1-9][0-9]*$"),]$QTimeout <- "30000"
}
if(is.null(practice$Sentence2)){
practice$Sentence2 <- ""
} else if(any(is.na(practice$Sentence2)) | any(practice$Sentence2 == "")) {
practice[is.na(practice$Sentence2) | practice$Sentence2 == "",]$Sentence2 <- ""
}
if(is.null(practice$Question)){
practice$Question <- ""
} else if(any(is.na(practice$Question)) | any(practice$Question == "")) {
practice[is.na(practice$Question) | practice$Question == "",]$Question <- ""
}
if(is.null(practice$LeftAnswer)){
practice$LeftAnswer <- ""
} else if(any(is.na(practice$LeftAnswer)) | any(practice$LeftAnswer == "")) {
practice[is.na(practice$LeftAnswer) | practice$LeftAnswer == "",]$LeftAnswer <- ""
}
if(is.null(practice$RightAnswer)){
practice$RightAnswer <- ""
} else if(any(is.na(practice$RightAnswer)) | any(practice$RightAnswer == "")) {
practice[is.na(practice$RightAnswer) | practice$RightAnswer == "",]$RightAnswer <- ""
}
if(is.null(practice$AnswerButton)){
practice$AnswerButton <- "leftTrigger"
} else if(any(is.na(practice$AnswerButton)) | any(practice$AnswerButton == "") | !all(practice$AnswerButton %in% c("A", "B", "X", "Y", "leftTrigger", "rightTrigger", "toggle", "mouse"))) {
practice$AnswerButton <- as.character(practice$AnswerButton)
practice[is.na(practice$AnswerButton) | practice$AnswerButton == "" | !(practice$AnswerButton %in% c("A", "B", "X", "Y", "leftTrigger", "rightTrigger", "toggle", "mouse")),]$AnswerButton <- "leftTrigger"
practice$AnswerButton <- as.factor(practice$AnswerButton)
}
}
# Stimuli defaults ####
{
# If any item numbers are not specified, exit ####
if(is.null(stimuli$item_id) | any(is.na(stimuli$item_id)) | any(stimuli$item_id == "") | !all(stimuli$item_id %like% "^[1-9][0-9]*$")){
cat("Error: item numbers not properly specified in experimental stimuli. ")
.Internal(.invokeRestart(list(NULL, NULL), NULL))
}
# If an experiment is not specified, attempt to calculate experiment numbers automatically ####
if((is.null(stimuli$Experiment) | any(is.na(stimuli$Experiment)) | any(stimuli$Experiment == "")) | !all(stimuli$Experiment %like% "^[1-9][0-9]*$")){
stimuli$Experiment <- ""
cat(sep = "", "Warning: Experiment numbers improperly set. Attempting to calculate automatically using item_id. Double-check ", filename, "-formatted.csv to ensure correct values.\n")
# Calculate item_condition numbers ####
stimuli$item_condition <- 0
# Set item_condition numbers for each item
current.item_condition <- 1
# For each row in the stimuli
for(i in 1:nrow(stimuli)){
# Set the item_condition of the row to the current item_condition, and increase that by one
stimuli[i,]$item_condition <- current.item_condition
current.item_condition <- current.item_condition + 1
# If there is a next row
if(!is.na(stimuli[i+1,]$item_condition)){
# If the item in the next row is different from the item in the current row
if(stimuli[i+1,]$item_id != stimuli[i,]$item_id){
# Reset current item_condition
current.item_condition <- 1
}
}
}
# Get a list of item_condition values for each item for the experiment ####
item_condition.per.item <- {}
# Set the initial maximum item_condition to 1
current.max.item_condition <- 1
# For each row in the stimuli
for(i in 1:nrow(stimuli)){
# If we're not on the last row
if(i < nrow(stimuli)){
# If the next row has a higher item_condition number
if(stimuli[i+1,]$item_condition > stimuli[i,]$item_condition){
# If that item_condition number is higher than the current max.item_condition, set the current max item_condition to that value
current.max.item_condition <- stimuli[i+1,]$item_condition
# Otherwise, if the next row has a lower or equal item_condition number
} else {
item_condition.per.item <- append(item_condition.per.item, current.max.item_condition)
current.max.item_condition <- 1
}
# If we're on the last row, add its item_condition as the maximum item_condition
} else {
item_condition.per.item <- append(item_condition.per.item, stimuli[i,]$item_condition)
}
}
# Set up a variable for the current experiment number ####
current.exp <- 1
# Set up a data frame to hold the stimuli with experiment numbers added
stimuli.with.exp <- data.frame()
# For each item, as designated by item_condition.per.item ####
for(i in 1:length(item_condition.per.item)){
# Get the current item and set its experiment to the current experiment
current.item <- stimuli %>%
slice(1:item_condition.per.item[i]) %>%
transform(Experiment = current.exp)
# Remove that item from the stimuli
stimuli <- stimuli %>% slice(-1:-item_condition.per.item[i])
# If we're not on the last item
if(i != length(item_condition.per.item)){
# If the next item has the same number of item_conditions as the current item
if(item_condition.per.item[i] == item_condition.per.item[i+1]) {
# Get the next item
next.item <- stimuli %>% slice(1:item_condition.per.item[i+1])
# If the next item number is less than or equal to the current item number
if(max(next.item$item_id) <= max(current.item$item_id)){
# Increase the experiment counter by one
current.exp <- current.exp + 1
}
} else {
# If the next item has a different number of item_conditions from the previous item, increase the experiment counter by one
current.exp <- current.exp + 1
}
}
stimuli.with.exp <- rbind(stimuli.with.exp, current.item)
}
# Bind the stimuli back together with practice items ####
stimuli.with.exp$item_condition <- as.character(stimuli.with.exp$item_condition)
stimuli <- stimuli.with.exp
}
stimuli <- stimuli %>% transform(Experiment = as.factor(Experiment))
# Check experiment numbers to make sure that they make sense ####
stimuli <- stimuli %>% arrange(Experiment)
# Get a list of the experiment numbers
exp.list <- levels((stimuli %>% droplevels())$Experiment)
# Temporarily transform experiment to a non-factor so we can add values to it if needed
stimuli$Experiment <- as.numeric(as.character(stimuli$Experiment))
# For each experiment
for(i in 1:length(exp.list)){
# If the current experiment's number doesn't match its position in the list, fix that
if(!(all(stimuli[stimuli$Experiment == exp.list[i],]$Experiment == i))){
cat(sep = "", "Warning: Renumbering experiment ", exp.list[i], " to experiment ", i, ". Experiment numbers should be consecutive integers starting at 1.\n")
stimuli[stimuli$Experiment == exp.list[i],]$Experiment <- i
}
}
stimuli$Experiment <- as.factor(stimuli$Experiment)
# Check item numbers to ensure they make sense ####
# Reorder just in case things are out of order
stimuli <- stimuli %>% arrange(Experiment, item_id)
# Set up a thing to hold the values
stimuli.fixed.items <- data.frame()
# For each experiment
for(i in 1:nlevels(stimuli$Experiment)){
# Get the current experiment
current.exp <- stimuli %>% filter(Experiment == i) %>% droplevels()
# Get a list of the levels of the item in the current experiment
item.list <- levels(current.exp$item_id %>% droplevels() %>% as.factor())
# For each item in that experiment
for(j in 1:length(item.list)){
current.item <- current.exp %>% filter(item_id == item.list[j]) %>% droplevels()
#If that item's number isn't equal to its position in the list
if(!(all(current.item$item_id == j))){
cat(sep = "", "Warning: Renumbering item ", item.list[j], " in experiment ", current.exp[1,]$Experiment, " to item ", j, ". For each experiment, items should be consecutive integers starting at 1.\n")
# Fix that
current.item$item_id <- j
}
# Add the current item to the fixed stimuli
stimuli.fixed.items <- rbind(stimuli.fixed.items, current.item)
}
}
stimuli <- stimuli.fixed.items
# Check to make sure all items in each experiment have the same number of rows/item_conditions, throw an error and exit if not ####
# For each experiment
for(i in 1:nlevels(stimuli$Experiment)){
# Get the current experiment
current.exp <- stimuli %>% filter(Experiment == i) %>% droplevels()
rows.per.item <- {}
# For each item
for(j in 1:nlevels(current.exp$item_id %>% droplevels() %>% as.factor())){
rows.per.item <- append(rows.per.item, nrow(current.exp %>% filter(item_id == j)))
}
# There's more than one value in rows.per.item, then not all items have equal numbers of item_conditions, and we exit
if(length(unique(rows.per.item)) != 1){
err.message <- ""
for(k in 1:length(unique(rows.per.item))){
err.message <- err.message %>% append(" ") %>% append(unique(rows.per.item)[k])
}
cat(sep = "", "Error: items in experiment ", as.character(current.exp[1,]$Experiment), " have differing numbers of item_conditions:", err.message, ". Each experiment must have the same number of item_conditions per item. ")
.Internal(.invokeRestart(list(NULL, NULL), NULL))
}
}
# Generate item_condition numbers per item per experiment ####
stimuli$item_condition <- 0
# For each experiment
for(i in 1:nlevels(stimuli$Experiment)){
# Get the number of rows per item (assume all items in one experiment have the same number of item_conditions)
item_condition.num <- nrow(stimuli %>% filter(Experiment == i, item_id == "1"))
# Set the item_condition number to repeat from 1 to the number of items for each item in the experiment
stimuli[stimuli$Experiment == i,]$item_condition <- rep(c(1:item_condition.num), nlevels((stimuli %>% filter(Experiment == i) %>% droplevels)$item_id %>% as.factor()))
}
stimuli$item_id <- stimuli$item_id %>% as.numeric()
stimuli$item_condition <- stimuli$item_condition %>% as.numeric()
# Remaining defaults ####
# If no sentences are specified, warn
if(is.null(stimuli$Sentence) | all(is.na(stimuli$Sentence)) | all(stimuli$Sentence == "")){
cat("Warning: No sentences specified.\n")
stimuli$Sentence <- ""
} else if(any(is.na(stimuli$Sentence)) | any(stimuli$Sentence == "")){
cat("Warning: Some sentences not specified.\n")
stimuli[is.na(stimuli$Sentence) | stimuli$Sentence == "", ]$Sentence <- ""
}
# Remove initial and final region specifiers, since we'll generate those automatically
stimuli$Sentence <- gsub("^/|/$", "", stimuli$Sentence)
if(is.null(stimuli$Timeout)){
stimuli$Timeout <- "30000"
} else if(any(is.na(stimuli$Timeout)) | any(stimuli$Timeout == "") | !all(stimuli$Timeout %like% "^[1-9][0-9]*$")) {
stimuli$Timeout <- as.character(stimuli$Timeout)
stimuli[is.na(stimuli$Timeout) | stimuli$Timeout == "" | !(stimuli$Timeout %like% "^[1-9][0-9]*$"),]$Timeout <- "30000"
}
if(is.null(stimuli$QTimeout)){
stimuli$QTimeout <- "30000"
} else if(any(is.na(stimuli$QTimeout)) | any(stimuli$QTimeout == "") | !all(stimuli$QTimeout %like% "^[1-9][0-9]*$")) {
stimuli$QTimeout <- as.character(stimuli$QTimeout)
stimuli[is.na(stimuli$QTimeout) | stimuli$QTimeout == "" | !(stimuli$QTimeout %like% "^[1-9][0-9]*$"),]$QTimeout <- "30000"
}
if(is.null(stimuli$Sentence2)){
stimuli$Sentence2 <- ""
} else if(any(is.na(stimuli$Sentence2)) | any(stimuli$Sentence2 == "")) {
stimuli[is.na(stimuli$Sentence2) | stimuli$Sentence2 == "",]$Sentence2 <- ""
}
if(is.null(stimuli$Question)){
stimuli$Question <- ""
} else if(any(is.na(stimuli$Question)) | any(stimuli$Question == "")) {
stimuli[is.na(stimuli$Question) | stimuli$Question == "",]$Question <- ""
}
if(is.null(stimuli$LeftAnswer)){
stimuli$LeftAnswer <- ""
} else if(any(is.na(stimuli$LeftAnswer)) | any(stimuli$LeftAnswer == "")) {
stimuli[is.na(stimuli$LeftAnswer) | stimuli$LeftAnswer == "",]$LeftAnswer <- ""
}
if(is.null(stimuli$RightAnswer)){
stimuli$RightAnswer <- ""
} else if(any(is.na(stimuli$RightAnswer)) | any(stimuli$RightAnswer == "")) {
stimuli[is.na(stimuli$RightAnswer) | stimuli$RightAnswer == "",]$RightAnswer <- ""
}
if(is.null(stimuli$AnswerButton)){
stimuli$AnswerButton <- "leftTrigger"
} else if(any(is.na(stimuli$AnswerButton)) | any(stimuli$AnswerButton == "") | !all(stimuli$AnswerButton %in% c("A", "B", "X", "Y", "leftTrigger", "rightTrigger", "toggle", "mouse"))) {
stimuli$AnswerButton <- as.character(stimuli$AnswerButton)
stimuli[is.na(stimuli$AnswerButton) | stimuli$AnswerButton == "" | !(stimuli$AnswerButton %in% c("A", "B", "X", "Y", "leftTrigger", "rightTrigger", "toggle", "mouse")),]$AnswerButton <- "leftTrigger"
stimuli$AnswerButton <- as.factor(stimuli$AnswerButton)
}
}
display.changes <- F
for(i in 1:nrow(stimuli)){
if(stimuli[i,]$Sentence2 != ""){
display.changes <- T
}
}
}
# Read in config file ####
cat("If you are using a config CSV file, enter its location (otherwise, press enter): ")
config.location <- readLines("stdin", n = 1)
if(config.location != "") { use.config <- T } else { use.config <- F }
if(use.config){
if(!(config.location %like% "\\.csv$")){
config.location <- paste(config.location, ".csv", sep = "")
}
while((!file.exists(config.location) & use.config) | config.location == paste(filepath, filename, ".csv", sep = "")){
if(config.location == paste(filepath, filename, ".csv", sep = "")){
cat("Config file cannot be the same as the stimuli file. Please enter a valid location: ")
config.location <- readLines("stdin", n = 1)
if(config.location != "") { use.config <- T } else { use.config <- F }
if(!(config.location %like% "\\.csv$")){
config.location <- paste(config.location, ".csv", sep = "")
}
} else {
cat("No config CSV file found at that location. Please enter a valid location: ")
config.location <- readLines("stdin", n = 1)
if(config.location != "") { use.config <- T } else { use.config <- F }
if(!(config.location %like% "\\.csv$")){
config.location <- paste(config.location, ".csv", sep = "")
}
if(!(config.location %like% "\\/|\\\\")){
config.location <- paste(sep = "", get_directory(), "/", config.location)
}
}
}
}
# If no config file is used, prompt for parameters ####
if(!use.config){
cat("Background color (name or hex)? ")
background.color <- readLines("stdin", n = 1)
if(background.color == ""){ background.color <- "white" }
while(!(background.color %in% colors()) &
!grepl("^((0x)|#|)[0-9A-Fa-f]{6}$", background.color)){
cat("Invalid background color. Please enter a valid background color: ")
background.color <- readLines("stdin", n = 1)
if(background.color == ""){ background.color <- "white" }
}
if(background.color %in% colors()){
background.color <- background.color %>% col2hex
}
background.color <- background.color %>% gsub("#|(0x)", "", .) %>% strtoi(base = 16)
cat("Text color (name or hex)? ")
foreground.color <- readLines("stdin", n = 1)
if(foreground.color == ""){ foreground.color <- "black" }
while(!(foreground.color %in% colors()) &
!grepl("^((0x)|#|)[0-9A-Fa-f]{6}$", foreground.color)){
cat("Invalid text color. Please enter a valid text color: ")
foreground.color <- readLines("stdin", n = 1)
if(foreground.color == ""){ foreground.color <- "black" }
}
if(foreground.color %in% colors()){
foreground.color <- foreground.color %>% col2hex
}
foreground.color <- foreground.color %>% gsub("#|(0x)", "", .) %>% strtoi(base = 16)
cat("Number of calibration points? ")
calibration.type <- readLines("stdin", n = 1)
if(calibration.type == ""){ calibration.type <- "9" }
while(!(calibration.type %in% c("3", "9", "13"))){
cat("Invalid response. Please enter one of: 3, 9, 13. ")
calibration.type <- readLines("stdin", n = 1)
if(calibration.type == ""){ calibration.type <- "9" }
}
calibration.type <- ifelse(calibration.type == "3", "0",
ifelse(calibration.type == "9", "1", "2"))
cat("Font name? ")
font <- readLines("stdin", n = 1)
if(font == ""){ font <- "Monaco" }
cat("Font size (pt)? ")
font.size <- readLines("stdin", n = 1)
if(font.size == ""){ font.size <- 12 }
while(!(font.size %like% "^[1-9][0-9]*$")){
cat("Invalid response. Please enter a number not starting with 0: ")
font.size <- readLines("stdin", n = 1)
if(font.size == ""){ font.size <- 12 }
}
cat("Font style? ")
font.weight <- readLines("stdin", n = 1)
if(font.weight == ""){ font.weight <- "normal non-italic" }
while(!(font.weight %in% c("normal non-italic", "normal italic", "bold non-italic", "bold italic"))){
cat("Invalid response. Please choose one of: normal non-italic, normal italic, bold non-italic, bold italic. ")
font.weight <- readLines("stdin", n = 1)
if(font.weight == ""){ font.weight <- "normal non-italic" }
}
cat("Font smoothing? ")
font.smoothing <- readLines("stdin", n = 1)
if(font.smoothing == ""){ font.smoothing <- "nonantialiased" }
while(!(font.smoothing %in% c("nonantialiased", "antialiased", "cleartype"))){
cat("Invalid response. Please enter one of: nonantialiased, antialiased, cleartype. ")
font.smoothing <- readLines("stdin", n = 1)
if(font.smoothing == ""){ font.smoothing <- "nonantialiased" }
}
cat("Which unit to use for line spacing, x offset, and y offset? ")
unit <- readLines("stdin", n = 1)
if(unit == ""){ unit <- "px" }
if(unit %like% "px|pix|pixel|pixels"){
unit <- "px"
use.pix <- T
} else if (unit %like% "pt|pts|point|points"){
unit <- "pt"
use.pix <- F
}
while(!(unit %like% "px|pt")){
cat("Invalid response. Please enter one of: px, pt. ")
unit <- readLines("stdin", n = 1)
if(unit == ""){ unit <- "px" }
if(unit %like% "px|pix|pixel|pixels"){
unit <- "px"
use.pix <- T
} else if (unit %like% "pt|pts|point|points"){
unit <- "pt"
use.pix <- F
}
}
cat("Line spacing (", unit, ")? ", sep = "")
line.spacing <- readLines("stdin", n = 1)
if(line.spacing == ""){ line.spacing <- "0" }
while(!(line.spacing %like% "^[0-9]+$")){
cat("Invalid response. Please enter a number: ")
line.spacing <- readLines("stdin", n = 1)
if(line.spacing == ""){ line.spacing <- "0" }
}
if(use.pix){
line.spacing.pix <- as.numeric(as.character(line.spacing))
line.spacing <- round(as.numeric(as.character(line.spacing))/1.32)
} else {
line.spacing.pix <- as.numeric(as.character(line.spacing)) * 1.32
}
cat("X offset (", unit, ")? ", sep = "")
x.offset <- readLines("stdin", n = 1)
if(x.offset == ""){ if(use.pix) { x.offset <- "20" } else { x.offset <- "15" }}
while(!(x.offset %like% "^[0-9]+$")){
cat("Invalid response. Please enter a number: ")
x.offset <- readLines("stdin", n = 1)
if(x.offset == ""){ if(use.pix) { x.offset <- "20" } else { x.offset <- "15" } }
}
if(use.pix){
x.offset.pix <- as.numeric(as.character(x.offset))
x.offset <- round(as.numeric(as.character(x.offset))/(1 + (1/3)))
} else {
x.offset.pix <- as.numeric(as.character(x.offset)) * (1 + (1/3))
}
cat("Y offset (", unit, ")? ", sep = "")
y.offset <- readLines("stdin", n = 1)
if(y.offset == ""){ if(use.pix) { y.offset <- "357" } else { y.offset <- "268" } }
while(!(y.offset %like% "^[0-9]+$")){
cat("Invalid response. Please enter a number: ")
y.offset <- readLines("stdin", n = 1)
if(y.offset == ""){ if(use.pix) { y.offset <- "357" } else { y.offset <- "268" } }
}
if(use.pix){
y.offset.pix <- as.numeric(as.character(y.offset))
y.offset <- round(as.numeric(as.character(y.offset))/(1 + (1/3)))
} else {
y.offset.pix <- as.numeric(as.character(y.offset)) * (1 + (1/3))
}
cat("Sentence button? ")
sentence.button <- readLines("stdin", n = 1)
if(sentence.button == ""){ sentence.button <- "rightTrigger" }
while(!(sentence.button %in% c("A", "B", "X", "Y", "leftTrigger", "rightTrigger", "toggle", "mouse"))){
cat("Invalid sentence button. Please enter a valid option (A, B, X, Y, leftTrigger, rightTrigger, toggle, mouse): ")
sentence.button <- readLines("stdin", n = 1)
if(sentence.button == ""){ sentence.button <- "rightTrigger" }
}
cat("Sentence trigger? ")
sentence.trigger <- readLines("stdin", n = 1)
if(sentence.trigger == ""){ sentence.trigger <- "driftandgaze" }
while(!(sentence.trigger %in% c("gaze", "nogaze", "driftcorrect", "driftandgaze"))) {
cat("Invalid response. Please choose one of: gaze, nogaze, driftcorrect, driftandgaze. ")
sentence.trigger <- readLines("stdin", n = 1)
if(sentence.trigger == ""){ sentence.trigger <- "driftandgaze" }
}
sentence.delay <- "0"
if(sentence.trigger %like% "nogaze"){
cat("Sentence delay (ms)? ")
sentence.delay <- readLines("stdin", n = 1)
if(sentence.delay == ""){ sentence.delay <- "0" }
while(!(sentence.delay %like% "^[0-9]*$")){
cat("Invalid response. Please enter a number: ")
sentence.delay <- readLines("stdin", n = 1)
if(sentence.delay == ""){ sentence.delay <- "0" }
}
}
cat("Sentence output? ")
sentence.output <- readLines("stdin", n = 1)
if(sentence.output == ""){ sentence.output <- "stream" }
while(!(sentence.output %in% c("stream", "nostream"))){
cat("Invalid response. Please choose one of: stream, nostream. ")
sentence.output <- readLines("stdin", n = 1)
if(sentence.output == ""){ sentence.output <- "stream" }
}
cat("Question trigger? ")
question.trigger <- readLines("stdin", n = 1)
if(question.trigger == ""){ question.trigger <- "nogaze" }
while(!(question.trigger %in% c("gaze", "nogaze", "driftcorrect", "driftandgaze"))) {
cat("Invalid response. Please choose one of: gaze, nogaze, driftcorrect, driftandgaze. ")
question.trigger <- readLines("stdin", n = 1)
if(question.trigger == ""){ question.trigger <- "nogaze" }
}
question.delay <- "0"
if(question.trigger %like% "nogaze"){
cat("Question delay (ms)? ")
question.delay <- readLines("stdin", n = 1)
if(question.delay == ""){ question.delay <- "0" }
while(!(question.delay %like% "^[0-9]*$")){
cat("Invalid response. Please enter a number: ")
question.delay <- readLines("stdin", n = 1)
if(question.delay == ""){ question.delay <- "0" }
}
}
cat("Question output? ")
question.output <- readLines("stdin", n = 1)
if(question.output == ""){ question.output <- "nostream" }
while(!(question.output %in% c("stream", "nostream"))){
cat("Invalid response. Please choose one of: stream, nostream. ")
question.output <- readLines("stdin", n = 1)
if(question.output == ""){ question.output <- "nostream" }
}
display.update.threshold <- "0"
display.revert <- "0"
dc.delay <- "0"
if(display.changes){
cat("How many horizontal pixels per character (make sure to check with your font and your monitor)? ")
h.pixels.per.char <- readLines("stdin", n = 1)
while(!(h.pixels.per.char %like% "^[1-9][0-9]*$")) {
cat("Invalid response. Please enter a number not starting with 0: ")
h.pixels.per.char <- readLines("stdin", n = 1)
}
h.pixels.per.char <- as.numeric(as.character(h.pixels.per.char))
cat("How many vertical pixels per character (make sure to check with your font and your monitor)? ")
v.pixels.per.char <- readLines("stdin", n = 1)
while(!(v.pixels.per.char %like% "^[1-9][0-9]*$")) {
cat("Invalid response. Please enter a number not starting with 0: ")
v.pixels.per.char <- readLines("stdin", n = 1)
}
v.pixels.per.char <- as.numeric(as.character(v.pixels.per.char))
cat("How much vertical padding around each character (", unit, ")? ", sep = "")
dcr.padding <- readLines("stdin", n = 1)
if(dcr.padding == "") { if(use.pix){ dcr.padding <- line.spacing.pix } else { dcr.padding <- line.spacing } } else if (dcr.padding == "line.spacing" | dcr.padding == "line spacing"){ if(use.pix){ dcr.padding <- line.spacing.pix } else {dcr.padding <- line.spacing } }
while(!(dcr.padding %like% "^[0-9]+$")){
cat("Invalid response. Please enter a number: ")
dcr.padding <- readLines("stdin", n = 1)
if(dcr.padding == "") { if(use.pix){ dcr.padding <- line.spacing.pix } else { dcr.padding <- line.spacing } } else if (dcr.padding == "line.spacing" | dcr.padding == "line spacing"){ if(use.pix){ dcr.padding <- line.spacing.pix } else {dcr.padding <- line.spacing } }
}
if(use.pix){
dcr.padding.pix <- as.numeric(as.character(dcr.padding))
dcr.padding <- round(as.numeric(as.character(dcr.padding))/1.32)
} else {
dcr.padding.pix <- as.numeric(as.character(dcr.padding)) * 1.32
}
cat("Display update threshold? ")
display.update.threshold <- readLines("stdin", n = 1)
if(display.update.threshold == "") { display.update.threshold <- "0" }
while(!(display.update.threshold %like% "^[0-9]*$")){
cat("Invalid response. Please enter a number: ")
display.update.threshold <- readLines("stdin", n = 1)
if(display.update.threshold == ""){ display.update.threshold <- "0" }
}
cat("Revert display changes? (T/F): ")
display.revert <- readLines("stdin", n = 1)
if(display.revert == ""){ display.revert <- F } else { display.revert <- display.revert %>% toupper() %>% as.logical() }
while(is.na(display.revert)){
cat("Invalid response. Please enter T or F: ")
display.revert <- readLines("stdin", n = 1)
if(display.revert == ""){ display.revert <- F } else { display.revert <- display.revert %>% toupper() %>% as.logical() }
}
if(display.revert){
cat("Display change reversion delay (ms)? ")
dc.delay <- readLines("stdin", n = 1)
if(dc.delay == ""){ dc.delay <- "0" }
while(!(dc.delay %like% "^[0-9]*$")){
cat("Invalid response. Please enter a number: ")
dc.delay <- readLines("stdin", n = 1)
if(dc.delay == ""){ dc.delay <- "0" }
}
}
if(display.revert){ display.revert <- "1" } else { display.revert <- "0" }
}
if((sentence.trigger %like% "gaze" & !(sentence.trigger %like% "nogaze")) |
(question.trigger %like% "gaze" & !(question.trigger %like% "nogaze"))){
cat("Automatically calculate gaze control rect params? (T/F): ")
calculate.gc.params <- readLines("stdin", n = 1)
if(calculate.gc.params == "") { calculate.gc.params <- F } else { calculate.gc.params <- calculate.gc.params %>% toupper() %>% as.logical() }
while(is.na(calculate.gc.params)){
cat("Invalid response. Please enter T or F: ")
calculate.gc.params <- readLines("stdin", n = 1)
if(calculate.gc.params == "") { calculate.gc.params <- F } else { calculate.gc.params <- calculate.gc.params %>% toupper() %>% as.logical() }
}
if (calculate.gc.params){
if(!exists("h.pixels.per.char")){
cat("How many horizontal pixels per character (make sure to check with your font and your monitor)? ")
h.pixels.per.char <- readLines("stdin", n = 1)
while(!(h.pixels.per.char %like% "^[1-9][0-9]*$")) {
cat("Invalid response. Please enter a number not starting with 0: ")
h.pixels.per.char <- readLines("stdin", n = 1)
}
}
h.pixels.per.char <- as.numeric(as.character(h.pixels.per.char))
if(!exists("v.pixels.per.char")){
cat("How many vertical pixels per character (make sure to check with your font and your monitor)? ")
v.pixels.per.char <- readLines("stdin", n = 1)
while(!(v.pixels.per.char %like% "^[1-9][0-9]*$")) {
cat("Invalid response. Please enter a number not starting with 0: ")
v.pixels.per.char <- readLines("stdin", n = 1)
}
}
v.pixels.per.char <- as.numeric(as.character(v.pixels.per.char))
gc.params <- paste(sep = " ",
round(y.offset.pix + ((line.spacing.pix+v.pixels.per.char)/2) - (v.pixels.per.char * 2)),
round(x.offset.pix),
round(y.offset.pix + ((line.spacing.pix+v.pixels.per.char)/2) + (v.pixels.per.char * 2)),
round(x.offset.pix + (h.pixels.per.char*4)))
} else {
cat("Gaze control rect params? ")
gc.params <- readLines("stdin", n = 1)
if(gc.params == ""){ gc.params <- "0 0 0 0" }
while(!(gc.params %like% "^([0-9]+ ){3}[0-9]+$")){
cat("Invalid response. Please enter four numbers separated by spaces to define the size of the gaze control box in the format Y1 X1 Y2 X2: ")
gc.params <- readLines("stdin", n = 1)
if(gc.params == ""){ gc.params <- "0 0 0 0" }
}
}
} else {
gc.params <- "0 0 0 0"
}
some.exp.uses.only.left.and.right <- F
left.or.right.list <- {}
for(i in 1:nlevels(stimuli$Experiment)){
if(all(stimuli[stimuli$Experiment == levels(stimuli$Experiment)[i],]$AnswerButton %in% c("leftTrigger", "rightTrigger"))){
some.exp.uses.only.left.and.right <- T
left.or.right.list <- append(left.or.right.list, i)
}
}
if(some.exp.uses.only.left.and.right){
cat("Balance order of correct answers within items for which experiments? Valid experiments are the following: ", paste(left.or.right.list, collapse = " "), ". ", sep = "")
balance.answer.order.exps <- readLines("stdin", n = 1)
if(paste(balance.answer.order.exps, collapse = "") != "") {
if(tolower(balance.answer.order.exps) == "all"){
balance.answer.order.exps <- left.or.right.list %>% unlist
} else if (balance.answer.order.exps == "none") {
balance.answer.order.exps <- ""
} else {
balance.answer.order.exps <- str_split(balance.answer.order.exps, " ") %>% unlist
}
}
while(paste(balance.answer.order.exps, collapse = "") != "" & (!all(grepl("^[1-9]*$", balance.answer.order.exps)) | !all(balance.answer.order.exps %in% left.or.right.list))){
cat("Invalid response. Please enter a list of experiment numbers separated by spaces, 'all', or 'none'. Valid experiments are the following: ", paste(left.or.right.list, collapse = " "), ". ", sep= "")
balance.answer.order.exps <- readLines("stdin", n = 1)
if(paste(balance.answer.order.exps, collapse = "") != "") { if(tolower(balance.answer.order.exps) == "all"){ balance.answer.order.exps <- left.or.right.list %>% unlist } else if (balance.answer.order.exps == "none") { balance.answer.order.exps <- "" } else { balance.answer.order.exps <- str_split(balance.answer.order.exps, " ") %>% unlist } }
}
} else {
balance.answer.order.exps <- ""
}
# for(i in 1:nlevels(stimuli$Experiment)){
# if(all(stimuli[stimuli$Experiment == i,]$Experiment %in% balance.answer.order.exps) &
# !all(stimuli[stimuli$Experiment == i,]$AnswerButton %in% c("leftTrigger", "rightTrigger"))){
# cat("Error: cannot balance answer order for answer buttons other than leftTrigger or rightTrigger. Not balancing answer order for experiment ", i, ".\n", sep = "")
# balance.answer.order.exps <- balance.answer.order.exps[balance.answer.order.exps != i]
# }
# }
some.exp.has.even.number <- F
even.number.list <- {}
for(i in 1:nlevels(stimuli$Experiment)){
if(max(stimuli[stimuli$Experiment == levels(stimuli$Experiment)[i],]$item_id) %% 2 == 0 &
max(stimuli[stimuli$Experiment == levels(stimuli$Experiment)[i],]$item_condition) %% 2 == 0){
some.exp.has.even.number <- T
even.number.list <- append(even.number.list, i)
}
}
if(some.exp.has.even.number){
cat("Pair items for which experiments?\nWarning: to work correctly, all item-related factors must have an even number of conditions. See scriptR manual for details.\nPossibly valid experiments are the following: ", paste(even.number.list, collapse = " "), ". ", sep = "")
paired.items.exps <- readLines("stdin", n = 1)
if(paste(paired.items.exps, collapse = "") != ""){ if (tolower(paired.items.exps) == "all"){ paired.items.exps <- even.number.list %>% unlist } else if (paired.items.exps == "none") { paired.items.exps = "" } else { paired.items.exps <- str_split(paired.items.exps, " ") %>% unlist } }
while(paste(paired.items.exps, collapse = "") != "" & (!all(grepl("^[1-9]*$", paired.items.exps)) | !all(paired.items.exps %in% even.number.list))) {
cat("Invalid response. Please enter a list of experiment numbers separated by spaces, 'all', or 'none'. Possibly valid experiments are the following: ", paste(even.number.list, collapse = " "), ". ", sep = "")
paired.items.exps <- readLines("stdin", n = 1)
if(paste(paired.items.exps, collapse = "") != ""){ if (tolower(paired.items.exps) == "all"){ paired.items.exps <- even.number.list %>% unlist } else if (paired.items.exps == "none") { paired.items.exps = "" } else { paired.items.exps <- str_split(paired.items.exps, " ") %>% unlist } }
}
} else {
paired.items.exps <- ""
}
# for(i in 1:nlevels(stimuli$Experiment)){
# # If we don't have an even number of items, remove that experiment from the list
# if(all(stimuli[stimuli$Experiment == levels(stimuli$Experiment)[i],]$Experiment %in% paired.items.exps) &
# (max(stimuli[stimuli$Experiment == levels(stimuli$Experiment)[i],]$item_id) %% 2 != 0) &
# (max(stimuli[stimuli$Experiment == levels(stimuli$Experiment)[i],]$item_condition) %% 2 != 0)) {
# cat("Warning: odd number of stimuli or conditions in experiment ", i, ". Unable to pair items for this experiment.\n", sep = "")
# # Remove that experiment from the paired items list
# paired.items.exps <- paired.items.exps[paired.items.exps != i]
# }
# }
cat("Generate sentences.txt base for sideeye? (T/F): ")
create.sentences.txt <- readLines("stdin", n = 1)
if(create.sentences.txt == "") { create.sentences.txt <- F } else { create.sentences.txt <- create.sentences.txt %>% toupper() %>% as.logical() }
while(is.na(create.sentences.txt)){
cat("Invalid response. Please enter T or F: ")
create.sentences.txt <- readLines("stdin", n = 1)
if(create.sentences.txt == "") { create.sentences.txt <- F } else { create.sentences.txt <- create.sentences.txt %>% toupper() %>% as.logical() }
}
if(create.sentences.txt){
# Check to see if analysis regions are the same for each item in an experiment, warn if not
for(i in 1:nlevels(stimuli$Experiment)){
current.sentences <- stimuli[stimuli$Experiment == i,]$Sentence
if(var(str_count(current.sentences, "/")) != 0){
cat("Warning: Unequal numbers of analysis regions specified in experiment ", i, ".\n", sep = "")
}
}
}
create.nogaze <- F
if (sentence.trigger != "nogaze" | question.trigger != "nogaze"){
cat("Create nogaze version? (T/F): ")
create.nogaze <- readLines("stdin", n = 1)
if(create.nogaze == ""){ create.nogaze <- F } else { create.nogaze <- create.nogaze %>% toupper() %>% as.logical() }
while(is.na(create.nogaze)){
cat("Invalid response. Please enter T or F: ")
create.nogaze <- readLines("stdin", n = 1)
if(create.nogaze == ""){ create.nogaze <- F } else { create.nogaze <- create.nogaze %>% toupper() %>% as.logical() }
}
}
create.test <- F
if(sentence.button != "mouse" | !all(stimuli$AnswerButton == "mouse")){
cat("Create testing version that uses only mouse clicks? (T/F): ")
create.test <- readLines("stdin", n = 1)
if(create.test == ""){ create.test <- F } else { create.test <- create.test %>% toupper() %>% as.logical() }
while(is.na(create.test)){
cat("Invalid response. Please enter T or F: ")
create.test <- readLines("stdin", n = 1)
if(create.test == ""){ create.test <- F } else { create.test <- create.test %>% toupper() %>% as.logical() }
}
}
cat("Create fix_align start pts matrix? (T/F): ")
create.fix.align.start.pts <- readLines("stdin", n = 1)
if(create.fix.align.start.pts == ""){ create.fix.align.start.pts <- T }
create.fix.align.start.pts <- create.fix.align.start.pts %>% toupper() %>% as.logical()
while(is.na(create.fix.align.start.pts)){
cat("Invalid response. Please enter T or F: ")
create.fix.align.start.pts <- readLines("stdin", n = 1)
if(create.fix.align.start.pts == ""){ create.fix.align.start.pts <- T } else { create.fix.align.start.pts <- create.fix.align.start.pts %>% toupper() %>% as.logical() }
}
if(create.fix.align.start.pts){
if(!exists("h.pixels.per.char")){
cat("How many horizontal pixels per character (make sure to check with your font and your monitor)? ")
h.pixels.per.char <- readLines("stdin", n = 1)
while(!(h.pixels.per.char) %like% "^[1-9][0-9]*$") {
cat("Invalid response. Please enter a number not starting with 0: ")
h.pixels.per.char <- readLines("stdin", n = 1)
}
}
h.pixels.per.char <- as.numeric(as.character(h.pixels.per.char))
if(!exists("v.pixels.per.char")){
cat("How many vertical pixels per character (make sure to check with your font and your monitor)? ")
v.pixels.per.char <- readLines("stdin", n = 1)
while(!(v.pixels.per.char %like% "^[1-9][0-9]*$")) {
cat("Invalid response. Please enter a number not starting with 0: ")
v.pixels.per.char <- readLines("stdin", n = 1)
}
}
v.pixels.per.char <- as.numeric(as.character(v.pixels.per.char))
}
cat("Save current settings as ", filename, "-config.csv? (T/F): ", sep = "")
save.settings <- readLines("stdin", n = 1)
if(save.settings == ""){ save.settings <- F } else { save.settings <- save.settings %>% toupper() %>% as.logical() }
while(is.na(save.settings)){
cat("Invalid response. Please enter T or F: ")
save.settings <- readLines("stdin", n = 1)
if(save.settings == ""){ save.settings <- F } else { save.settings <- save.settings %>% toupper() %>% as.logical() }
}
}
}
# Settings when using config file ####
# If using a config file, read it in and transfrom the necessary parameters
if(use.config){
config <- read.csv(config.location)
if(is.null(config$option) | all(config$option == "") | all(is.na(config$option))){
cat("Error: options column missing or unspecified. ")
.Internal(.invokeRestart(list(NULL, NULL), NULL))
}
config <- config %>% filter(option %in% c("background.color", "foreground.color", "calibration.type",
"font", "font.size", "font.weight", "font.smoothing", "unit",
"line.spacing", "x.offset", "y.offset", "sentence.button",
"sentence.trigger", "sentence.delay", "sentence.output",
"question.trigger", "question.delay", "question.output",
"calculate.gc.params", "gc.params", "h.pixels.per.char",
"v.pixels.per.char", "dcr.padding", "display.update.threshold",
"display.revert", "dc.delay", "create.sentences.txt",
"create.nogaze", "create.test", "create.fix.align.start.pts",
"paired.items.exps", "balance.answer.order.exps"))
if(is.null(config$setting) | all(config$setting == "") | all(is.na(config$setting))){
cat("Warning: settings column missing or unspecified. Using all defaults.\n")
config$setting <- ""
}
# If an option is specified twice
if(length(config$option) != length(unique(config$option))){
# Find the duplicated value
n.occur <- data.frame(table(config$option))
duplicates <- n.occur[n.occur$Freq > 1,]$Var1 %>% paste(collapse = ", ")
cat("Error: option(s) specified multiple times: ", duplicates, ". ", sep = "")
.Internal(.invokeRestart(list(NULL, NULL), NULL))
} else {