Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Changes in version 1.0.6 (release date:??-??-2025)

- Actical: Improve detection of recording start #85

# Changes in version 1.0.5 (release date:09-05-2025)

- Fitbit: Now also loads heart rate data #78
Expand Down
24 changes: 22 additions & 2 deletions R/findStartData.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
findStartData = function(filename, quote, startindex) {
findStartData = function(filename, quote, startindex, blockname = NULL) {
# Function used to find start of time series in Actiwatch and Actical data
# ! Assumptions that timeseries start before line 1000
if (!is.null(blockname)) {
# Default approach when blockname is specified (used for Actical)
# ! Assumption that time series start in first 3000 lines
# ! Assumption count data are preceded by a block header with name blockname
data_head = data.table::fread(input = filename,
header = FALSE, sep = ",",
nrows = 3000, data.table = FALSE,
quote = quote, fill = TRUE)
block_start = grep(pattern = blockname, x = data_head[, 1], ignore.case = TRUE)
if (length(block_start) != 0) {
block_head = data_head[(block_start + 1):(block_start + 20), 1]
block_head = unlist(lapply(block_head, FUN = function(x) unlist(strsplit(x, ","))[1]))
epochnumbers = suppressWarnings(as.numeric(block_head))
block_start = block_start + which(!is.na(epochnumbers))[1]
}
if (length(block_start) != 0) return(block_start)
startindex = block_start
}
# Original approach:
# ! Assumption that timeseries start before line 1000
# ! Assumption that epoch column start with 1
while (startindex > 0) {
testraw = data.table::fread(input = filename,
header = FALSE, sep = ",", skip = startindex,
Expand Down
4 changes: 2 additions & 2 deletions R/readActicalCount.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readActicalCount = function(filename = NULL,
# ! Assumptions that timeseries start before line 1000
startindex = 300
quote = detectQuote(filename = filename, skip = startindex)
startindex = findStartData(filename, quote, startindex)
startindex = findStartData(filename, quote, startindex, blockname = "epoch-by-epoch")
# -1 because Actical starts at epoch 0 while function looks for epoch 1
startindex = startindex - 1
D = data.table::fread(input = filename, sep = ",", skip = startindex,
Expand All @@ -29,7 +29,7 @@ readActicalCount = function(filename = NULL,
colnames = data.table::fread(input = filename, data.table = FALSE,
header = FALSE, sep = ",",
skip = dashedLineIndex + 1,
nrows = (startindex - dashedLineIndex) - 2, quote = quote)
nrows = (startindex - dashedLineIndex) - 2, quote = quote, fill = TRUE)
collapse = function(x) {
return(paste0(x, collapse = "_"))
}
Expand Down
2 changes: 1 addition & 1 deletion R/readAxivity.R
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ readAxivity = function(filename, start = 0, end = 0, progressBar = FALSE, desire
stop("At least file must be specified")
}
# Get file size in data blocks
numDBlocks = round(file.info(filename)$size / blockBytes) - 2
numDBlocks = round(file.size(filename) / blockBytes) - 2
# Open file
fid = file(filename,"rb")
on.exit({
Expand Down
6 changes: 5 additions & 1 deletion man/findStartData.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Actiwatch and Actical data.
}
\usage{
findStartData(filename, quote, startindex)
findStartData(filename, quote, startindex, blockname = NULL)
}
\arguments{
\item{filename}{
Expand All @@ -21,6 +21,10 @@
Start index where to start searching. For Actical we start at 300 while
for Actiwatch we start at 1000.
}
\item{blockname}{
Character with name of data block to search for.
For Actical we use "epoch-by-epoch".
}
}
\value{
Start index
Expand Down
Loading