PCdLf / wearables

Functions for reading e4 data, and create several parameters for analysis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Empty IBI file

SJKOL opened this issue · comments

It can happen that the Empatica IBI file is completely empty (no header). read_e4 cannot handle this and crashes.

Our solution:

#check if file has data first
  mtry <- try(read.csv(paste0(folder, '/', file), nrows = 1, header = FALSE), silent = TRUE)
  
  if (class(mtry) == "try-error") {
    message("Problem with IBI file.")
    data <- NULL

Todo: integrate into read_e4 function where IBI is read.

In E4tools probably:

#check if file has data first
mtry <- try(read.csv(file.path(out_dir, "IBI.csv"),
                  stringsAsFactors = FALSE,
                  header = FALSE, skip = 1),
    silent = TRUE)
  
if (class(mtry) == "try-error") {
    message("Problem with IBI file.")
    ibi <- NULL
else {
  ibi_timestart <- get_timestart(file.path(out_dir, "IBI.csv"))
  timestart <- c(timestart, list(IBI = ibi_timestart))

  ibi <- cbind(data.frame(DateTime = as_time(ibi_timestart, tz = tz) + ibi[[1]]),
                          seconds = ibi[[1]],
                          IBI = ibi[[2]])
}

(Sry no time to change it in code now.)

Fixed. read_e4 returns NULL and a warning if one or more of the data files are empty (1 or 0 lines)

E4 dashboard now skips .zip files that don't contain IBI data. Ideally we want to calculate the other parameters besides IBI, and throw NA for IBI if its empty.

The batch analysis skips the right files that have no data in it. However, a problem still occurs if the HRV algorithm is unable to interpolate the vector. In the accompanying file the IBI.csv consists of 4 rows, but after interpolation, only 1 remains. Need to fix this.
1635148245_A00204_11.zip

Fixed with dad2c47