From 43428d4db013759b731e93b2d49adf4634d32336 Mon Sep 17 00:00:00 2001 From: Vincent van Hees Date: Fri, 27 Sep 2024 10:59:32 +0200 Subject: [PATCH] correct startindex for Actical which starts at epoch zero instead of 1 #68 --- R/readActicalCount.R | 2 ++ tests/testthat/test_readActicalCount.R | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/R/readActicalCount.R b/R/readActicalCount.R index 9896ddd..337c1e9 100644 --- a/R/readActicalCount.R +++ b/R/readActicalCount.R @@ -7,6 +7,8 @@ readActicalCount = function(filename = file, desiredEpochSize = NULL, startindex = 300 quote = detectQuote(fn = filename, index = startindex) startindex = findStartData(filename, quote, startindex) + # -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, quote = quote, data.table = FALSE) # ! Assumption that column names are present 2 lines prior to timeseries diff --git a/tests/testthat/test_readActicalCount.R b/tests/testthat/test_readActicalCount.R index f8dbd2d..626a606 100644 --- a/tests/testthat/test_readActicalCount.R +++ b/tests/testthat/test_readActicalCount.R @@ -4,17 +4,17 @@ test_that("Actical csv is correctly read", { file = system.file("testfiles/Actical.csv", package = "GGIRread") D = readActicalCount(filename = file, desiredEpochSize = 60, timeformat = "%d-%b-%y %H:%M", tz = "") expect_equal(D$epochSize, 60) - expect_equal(format(D$startTime), "2021-05-13 00:01:00") - expect_equal(nrow(D$data), 500) + expect_equal(format(D$startTime), "2021-05-13") + expect_equal(nrow(D$data), 501) expect_equal(ncol(D$data), 2) - expect_equal(sum(D$data, na.rm = TRUE), 8174) + expect_equal(sum(D$data, na.rm = TRUE), 8436) D = readActicalCount(filename = file, desiredEpochSize = 120, timeformat = "%d-%b-%y %H:%M", tz = "") expect_equal(D$epochSize, 120) - expect_equal(format(D$startTime), "2021-05-13 00:01:00") + expect_equal(format(D$startTime), "2021-05-13") expect_equal(nrow(D$data), 250) expect_equal(ncol(D$data), 2) - expect_equal(sum(D$data, na.rm = TRUE), 8174) + expect_equal(sum(D$data, na.rm = TRUE), 8436) }) test_that("Actical csv error correctly", {