|
1 | | -findStartData = function(filename, quote, startindex) { |
| 1 | +findStartData = function(filename, quote, startindex, blockname = NULL) { |
2 | 2 | # Function used to find start of time series in Actiwatch and Actical data |
3 | | - # ! Assumptions that timeseries start before line 1000 |
| 3 | + if (!is.null(blockname)) { |
| 4 | + # Default approach when blockname is specified (used for Actical) |
| 5 | + # ! Assumption that time series start in first 3000 lines |
| 6 | + # ! Assumption count data are preceded by a block header with name blockname |
| 7 | + data_head = data.table::fread(input = filename, |
| 8 | + header = FALSE, sep = ",", |
| 9 | + nrows = 3000, data.table = FALSE, |
| 10 | + quote = quote, fill = TRUE) |
| 11 | + block_start = grep(pattern = blockname, x = data_head[, 1], ignore.case = TRUE) |
| 12 | + if (length(block_start) != 0) { |
| 13 | + block_head = data_head[(block_start + 1):(block_start + 20), 1] |
| 14 | + block_head = unlist(lapply(block_head, FUN = function(x) unlist(strsplit(x, ","))[1])) |
| 15 | + epochnumbers = suppressWarnings(as.numeric(block_head)) |
| 16 | + block_start = block_start + which(!is.na(epochnumbers))[1] |
| 17 | + } |
| 18 | + if (length(block_start) != 0) return(block_start) |
| 19 | + startindex = block_start |
| 20 | + } |
| 21 | + # Original approach: |
| 22 | + # ! Assumption that timeseries start before line 1000 |
| 23 | + # ! Assumption that epoch column start with 1 |
4 | 24 | while (startindex > 0) { |
5 | 25 | testraw = data.table::fread(input = filename, |
6 | 26 | header = FALSE, sep = ",", skip = startindex, |
|
0 commit comments