Closed juthzi closed 3 years ago
You might want to head over to the https://www.sr-support.com/ and ask them about recovering the ID--they are really great.
My suggestion is that you should just use item as you trial id variable.
Thank you for the advice! The people from SR support are indeed very helpful! They suggested to use the Variable "!MODE RECORD CR 1000 2 1 L" instead of "TRIALID", because this should (at least in my files) be always logged with each trial as well. But yes, I could also use "item", as you suggested.
However, I still have problems inplementing this. When I use the function find_messages_edf(), I get an error message when including "!MODE RECORD CR 1000 2 1 L" as a search pattern.
find_messages_edf(file_list = file_list_edf, varnames = c("TRIALID", "mode_variable", "condition", "item", "keypress"), patterns = c("TRIALID", "!MODE RECORD CR 1000 2 1 L", "!V TRIAL_VAR condition", "!V TRIAL_VAR item", "!V TRIAL_VAR keypress"), output_dir_behave_data)
Also, I cannot simply remove the TRIALID-variable, I think the function searches for it automatically. When I remove the TRIALID variable from the function, I get the following error:
Error: Can't rename columns that don't exist.
x Column TRIALID
doesn't exist.
You will need to actually change the function itself. I suggest changing TRIALID below to mode_variable and it should work:
find_messages_edf <- function(file_list,varnames,patterns, output_dir)
{
subs <- length(file_list)
for (sub in 1:subs) {
subject = basename(file_list[sub]) # get id from file
msg=edf.messages.c(file_list[sub])
messagelist = list()
for(i in 1:length(varnames)){
find_msg <- msg$msg %>%
subset(str_detect(string=., pattern=varnames[i])) %>% # find specific pattern
str_replace(pattern=patterns[i], replacement = "") %>% # replace pattern with white space
str_replace_all(pattern=" ", repl="") # get rid of white space
messagelist[[i]]<-find_msg
}
message_data=dplyr::bind_cols(messagelist) %>%
set_names(varnames) %>%
dplyr::mutate(subject=as.factor(subject)) %>%
dplyr::rename(trial = "mode_variable")%>% #I changed this from TRIALID to mode_variable
dplyr::mutate(trial=as.integer(trial))
subOutData <- file.path(output_dir, paste(file_list[sub], "_behave_data.csv", sep="")) # save file
write.table(message_data, file = subOutData, append = FALSE, sep = ",",
row.names = FALSE, col.names = TRUE)
}
}
Great, thank you! It works now. There was some strange behaviour still, so instead of "mode_variable", I entered "!MODE RECORD CR 1000 2 1 L" in the line you changed above and in the following used the following code for extracting bebavioural data:
find_messages_edf_ADJUSTED(file_list = file_list_edf, varnames = c("!MODE RECORD CR 1000 2 1 L", "condition", "item", "keypress"), patterns = c("!MODE RECORD CR 1000 2 1 L", "!V TRIAL_VAR condition", "!V TRIAL_VAR item", "!V TRIAL_VAR keypress"), output_dir_behave_data)
I have to add that also with "!MODE RECORD CR 1000 2 1 L", it did not work for all of my files. Therefore, I am now using the item variable after all, which seems to be present for all of the trials.
I would like to use the function find_messages_edf(), which worked for some of my files. However, when I wanted to process all of them, I get the following error message:
Error: Can't recycle
..1
(size 95) to match..2
(size 96).Investigating the files, I found that the csv, which I created earlier in the script from the edf file, contains the expected 96 trials, whereas there are only 95 instances of "TRIALID" in the asc file I created from my edf file (because I cannot read the edf file with a text program). Investigating further, I found that apparently in some of my edf files, the first or last TRIALID-message was not logged. I do not know why this would happen, maybe because I did not hand over the actual number of the trial in my experiment script, so it only loggs "TRIALID", but not the actual number associated with it? The behaviour is odd also because the rest of the trial's messages were logged (e.g. the 96 objects pertaining to the 96 trials are always logged). I could alter the asc files manually (adding an extra line of message with "TRIALID"), to make the function work on my files. However, I do not know of a way to alter edf files. Does anyone have an idea?