Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

If a researcher is interested in certain time periods of an eye-tracking recording, such as problem-solving phases in education studies, he/she can replay the recording, generate segments or scenes, and then export the relevant data. However, this process is time-consuming. Using R may provide a way to quickly obtain and organize such data (when the definitions of time periods are clear). Here I use the text files exported by Tobii Studio as an example.
Suppose there are 15 .tsv files (which can be considered as .txt files) in a local folder “D:\tsv-aoi”. Each file contains the recording of a participant in an eye-tracking experiment.

The first step is to get all the 15 file names:

###### setwd(“D:/txt-aoi/”)filenames <- list.files(full.names=TRUE)

Each file looks like:

If we plan to obtain information between the first AOI11_1 (Timesamp=306913 in the above file) and the first AOI11_1 coming back (Timesamp=319356 in the above file), the next step is to read all 15 files into (a list of) data frames (notice the first 11 lines in each file are not needed), get the “Timestamp” and “AoiNames” columns for AOI11’s only.

###### aoiFiles <- lapply(filenames, function(x){                      read.table(x, header=TRUE,  sep=”\t”, skip=11) })aoiFiles_q11 <- lapply(aoiFiles, function(x){                               x[grep(“tor11.html”, x$StimuliName), c(1,4)]})aoiFiles_q11 The result (showing from one of the 15 files): We may remove consecutive duplicate AOIs from each data frame: ###### RmRepeat <- function(df, n){ X <- rle(as.character(df[,n])) Y <- cumsum(c(1, X$lengths[-length(X\$lengths)]))   return(df[Y,])}aoiFiles_q11rd <- lapply(aoiFiles, function(x) RmRepeat(x, 2))aoiFiles_q11rd

The final result (one of the 15) is shown below. From there we can analyze eye-tracking measures such as fixation duration and scanpath between the 2 red time stamps.