Load Eyelink data into R (in a very fast way)

These scripts are adapted from Dr. Jason Forte’s work in our lab.

R

## eyelink data analysis 
setwd('/Users/JianChen/Dropbox/PhD/Exp1/')
filenameASC = 'xxxxxx.asc'
dataEyelink
# extract all numeric lines & replace blink (.) with 0.0\. Hack: sed
# ''s/\.//g'' gets rid of all decimal points. We correct for that in the line dataEyelink$samples$V2 & V3
# system command in this case = sed -n '/^\[0-9]/p' PH12J17a.asc | sed 's/ \./0.0/g' | sed 's/\.//g' > tmp.txt
system(paste("sed -n '/^\[0-9]/p'", filenameASC, " | sed 's/\\./0.0/g' "," | sed 's/\\.//g' > tmp.txt"))
# read samples into data structure
dataEyelink$samples <- read.table('tmp.txt')
# correct for above hack to resote pixel values....
dataEyelink$samples$V2 <- dataEyelink$samples$V2 / 10
dataEyelink$samples$V3 <- dataEyelink$samples$V3 / 10
# extract gaze event for "EFIX" & remove "EFIX R" (Here I tracked right eye)
system(paste("sed -n -e '/^EFIX/p' ", filenameASC, " | sed 's/EFIX R //g' > tmp.txt"))
# read fixations into data structure
dataEyelink$fixations <- read.table('tmp.txt')

# extract gaze event for "ESACC" & remove "ESACC R"
system(paste("sed -n -e '/^ESACC/p' ", filenameASC, " | sed 's/ESACC R //g' > tmp.txt"))
# read saccades into data structure
dataEyelink$saccades <- read.table('tmp.txt')

# extract gaze event for "EBLINK" & remove "EBLINK R"
system(paste("sed -n -e '/^EBLINK/p' ", filenameASC," | sed 's/EBLINK R //g' > tmp.txt"))
# read blinks into data structure
dataEyelink$blinks <- read.table('tmp.txt')

# extract trigger event for "SYNCTIMEON" & "SYNCTIMEOFF" convert "SYNCTIMEON" to 1 & "SYNCTIMEOFF" to 0 and remove MSG
system(paste("sed -n -e '/SYNCTIMEON/p' -e '/SYNCTIMEOFF/p' ", filenameASC, " | sed 's/SYNCTIMEON/1/g' | sed 's/SYNCTIMEOFF/0/g' | sed 's/MSG //g' > tmp.txt"))
# read triggers into data structure
dataEyelink$triggers <- read.table('tmp.txt')

system('rm tmp.txt')