hermesh2
11/21/2015 - 5:05 PM

Blog005 01 read data.R

needed <- list("dplyr", "data.table", # Libraries for data mining
               "jpeg", "ggplot2", "png", "grid", "geoR", "rgl", # Libraries for 
               "repmis" # Libraries for web scrapping [3]
               )

if(FALSE){ # If you want to install change for TRUE
  lapply(X = needed ,FUN = 
           function(x){
             if(!require(x, character.only = T)){
               install.packages(x)
             }
             library(x,character.only = T)
           })
}else{
  lapply(X = needed ,FUN = 
            function(x){
              library(x,character.only = T)
           })
}

dir <- # "C:/Users/Javier Villacampa/Dropbox/Chabi/Blog/Eye track/"
  "C:/Users/usuario/Dropbox/Chabi/Blog/Eye track/" # Put your dir
setwd(dir)
dir.create(path = "Results")
dir.create(path = "Data")
rm(list = ls()); gc()


# S read data -------------------------------------------------------------
# Download the image
url <- "http://2.bp.blogspot.com/-Qo8JF_ux808/VlEAanXvltI/AAAAAAAACds/TkzNkifUK4M/s1600/Imagen1.jpeg"
download.file(url = url, destfile = "Data/Imagen1.jpeg", mode = "wb")


image_1 <- readJPEG( source = "Data/Imagen1.jpeg")
image_1 <- rasterGrob(image = image_1, interpolate=TRUE)
# Download the csv from dropbox
d <- repmis::source_DropboxData(file = "sample-1.txt", key = "1s4uo7u340snqtv", sep ="\t") %>% data.table()
# E read data -------------------------------------------------------------



# S Clean data ------------------------------------------------------------
d[ , TRIAL_INDEX := factor(TRIAL_INDEX)] 
d[ , Subject := factor(Subject)]
d <- d[ d$CURRENT_FIX_X <= 1000 & d$CURRENT_FIX_X  >= 0 & 
          d$CURRENT_FIX_Y <= 700 & d$CURRENT_FIX_Y  >= 0,   ]
# S Clean data ------------------------------------------------------------


# S Plot ------------------------------------------------------------------
d <- d %>% data.frame()

d2 <- copy(d) # Save a copy from the old data
d <- d2[, c("CURRENT_FIX_X", "CURRENT_FIX_Y")]
# E Plot ------------------------------------------------------------------