This script puts all eprime data files into R and selects columns of interest for a new data frame. Before you run it, please ensure all of the .txt files are in the current project folder.
# Let's use 3 packages.
library(tidyverse)
library(rprime)
library(wrapr)
# A function to prepare all eprime data simultaneously
reduce_wm <- function(wm_path) {
# Read in a text file generated by Eprime
wm_lines <- read_eprime(wm_path)
# Convert lines from an Eprime file into EprimeFrame objects
wm_frames <- FrameList(wm_lines)
# Make it a data frame.
experiment_df <- to_data_frame(wm_frames)
# Select the columns we want for a tibble called "dat".
dat <- as.tibble(experiment_df) %>%
select(qc(
Sample, TrialType, Prime, Proc1, Proc2, Proc3, Proc4, Proc5, Target,
Proc1.RT, Proc2.RT, Proc3.RT, Proc4.RT,
Proc1VALIDCR, Proc2VALIDCR, Proc3VALIDCR, Proc3VALIDCR,
MemTarget.RT, MemTarget.ACC
))
# Only put the actual trials in "dat".
dat <- dat[14:93, ]
}
# Does it work on one eprime text file?
test_dat <- reduce_wm("ProjectWM- Final test-12-1.txt")
# How many rows in this data frame with 1 participant?
nrow(test_dat)
[1] 80
Gather a pointer to all of the .txt data files from EPrime.
# Find all file names ending in .txt located in the current project folder.
files <- dir(pattern = "*.txt")
files
[1] "ProjectWM- Final test-11-1.txt" "ProjectWM- Final test-12-1.txt"
[3] "ProjectWM- Final test-13-1.txt" "ProjectWM- Final test-14-1.txt"
[5] "ProjectWM- Final test-15-1.txt" "ProjectWM- Final test-16-1.txt"
[7] "ProjectWM- Final test-17-1.txt" "ProjectWM- Final test-18-1.txt"
[9] "ProjectWM- Final test-19-1.txt" "ProjectWM- Final test-20-1.txt"
[11] "ProjectWM- Final test-21-1.txt" "ProjectWM- Final test-22-1.txt"
[13] "ProjectWM- Final-001-1.txt" "ProjectWM- Final-002-1.txt"
[15] "ProjectWM- Final-003-1.txt" "ProjectWM- Final-004-1.txt"
# How many individual data files from eprime do we have?
length(files)
[1] 16
Use reduce_wm() as the function repeated for the files we found.
# Apply the map_df function to use reduce_wm() on each participant's text file from eprime.
test_dats <- map_df(files, reduce_wm)
Does our expectation of observations in the data at hand match with the number of rows?
# How many rows in this data frame with 2 participants?
nrow(test_dats)
[1] 1280
# Let's review the variable/column names in the data.
names(test_dats)
[1] "Sample" "TrialType" "Prime" "Proc1"
[5] "Proc2" "Proc3" "Proc4" "Proc5"
[9] "Target" "Proc1.RT" "Proc2.RT" "Proc3.RT"
[13] "Proc4.RT" "Proc1VALIDCR" "Proc2VALIDCR" "Proc3VALIDCR"
[17] "MemTarget.RT" "MemTarget.ACC"
Now, using these variables we can begin exploration, visualization, and analysis.