From e2f928c2b57fda9f60b4c1c66494f2dabf7e06a0 Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Tue, 5 May 2026 14:22:07 -0400 Subject: [PATCH 1/8] added a test --- DESCRIPTION | 3 ++- R/agread.R | 10 +++++----- tests/testthat/test_agread.R | 3 +++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7472a52..fc68269 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,13 +1,14 @@ Package: agcounts Type: Package Title: Calculate 'ActiGraph' Counts from Accelerometer Data -Version: 0.6.9 +Version: 0.7.0 Authors@R: c( person(c("Brian", "C."), "Helsel", email = "bhelsel@kumc.edu", role = c("aut", "cre")), person(c("Paul", "R."), "Hibbing", role = "ctb"), person(c("Robert N."), "Montgomery", role = "ctb"), person(c("Eric D."), "Vidoni", role = "ctb"), person("Jonathan", "Clutton", role = "ctb"), + person("John", "Muschelli", role = "ctb"), person("University of Kansas", role = "cph") ) Description: Calculate 'ActiGraph' counts from the X, Y, and Z axes of a triaxial diff --git a/R/agread.R b/R/agread.R index 243d42f..0aefe17 100644 --- a/R/agread.R +++ b/R/agread.R @@ -30,9 +30,9 @@ agread <- function(path, parser = c("pygt3x", "GGIR", "read.gt3x"), tz = "UTC", parser <- "GGIR" } switch(parser, - "pygt3x" = .pygt3xReader(path = path, verbose = verbose, ...), - "GGIR" = .ggirReader(path = path, verbose = verbose, ...), - "read.gt3x" = .gt3xReader(path = path, verbose = verbose, ...), + "pygt3x" = .pygt3xReader(path = path, verbose = verbose, tz = tz, ...), + "GGIR" = .ggirReader(path = path, verbose = verbose, tz = tz, ...), + "read.gt3x" = .gt3xReader(path = path, verbose = verbose, tz = tz, ...), stop("No method exists yet for ", sQuote(parser), call. = FALSE) ) } @@ -56,7 +56,7 @@ agread <- function(path, parser = c("pygt3x", "GGIR", "read.gt3x"), tz = "UTC", # Return Data colnames(raw) <- c("time", "X", "Y", "Z") raw$time <- as.POSIXct(raw$time, origin = "1970-01-01 00:00:00", tz=tz) - meta <- read.gt3x::parse_gt3x_info(path) + meta <- read.gt3x::parse_gt3x_info(path, tz = tz) attr(raw, "start_time") <- meta$`Start Date` %>% lubridate::force_tz(tz) attr(raw, "stop_time") <- meta$`Stop Date` %>% lubridate::force_tz(tz) raw @@ -66,7 +66,7 @@ agread <- function(path, parser = c("pygt3x", "GGIR", "read.gt3x"), tz = "UTC", if(verbose) print("Reading data with read.gt3x and calibrating with GGIR.") I <- GGIR::g.inspectfile(datafile = path) C <- GGIR::g.calibrate(datafile = path, use.temp = FALSE, printsummary = FALSE, inspectfileobject = I) - raw <- read.gt3x::read.gt3x(path, asDataFrame = TRUE, imputeZeroes = TRUE) + raw <- .gt3xReader(path, tz = tz, verbose = verbose, ...) raw[, 2:4] <- scale(raw[, 2:4], center = -C$offset, scale = 1/C$scale) if(C$nhoursused==0) message("\n There is not enough data to perform the GGIR autocalibration method. Returning data as read by read.gt3x.") raw diff --git a/tests/testthat/test_agread.R b/tests/testthat/test_agread.R index 7a9c367..e0ee9a3 100644 --- a/tests/testthat/test_agread.R +++ b/tests/testthat/test_agread.R @@ -21,6 +21,9 @@ testthat::test_that("Check that data can be read into agcounts using each agread expect_equal(nrow(rawData), 18000) expect_equal(ncol(rawData), 4) + invisible(capture.output(rawData <- agread(path = file, parser = "read.gt3x", verbose = FALSE, tz = "EST"))) + expect_true(lubridate::tz(rawData$time) == "EST") + raw <- read.gt3x(path = file, asDataFrame = TRUE) sf <- agcounts:::.get_frequency(raw) invisible(capture.output(agcalibrated <- agcalibrate(raw))) From c05fc4f4597dba1000e2588cc2287eb31208cbca Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Tue, 5 May 2026 14:22:25 -0400 Subject: [PATCH 2/8] added DESCRIPTION --- DESCRIPTION | 1 - 1 file changed, 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index fc68269..882f054 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,7 +21,6 @@ Depends: License: MIT + file LICENSE Encoding: UTF-8 LazyData: true -RoxygenNote: 7.3.1 Imports: data.table, gsignal, From d40a8c3c0e57418d0d2b420051e458803a0ed4a8 Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Wed, 20 May 2026 14:33:23 -0400 Subject: [PATCH 3/8] new roxygen --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index 882f054..8ecce85 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -54,3 +54,4 @@ LinkingTo: RcppArmadillo URL: https://github.com/bhelsel/agcounts BugReports: https://github.com/bhelsel/agcounts/issues +Config/roxygen2/version: 8.0.0 From faa9584c4dc86182a559e54723e2293235c2bde0 Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Wed, 20 May 2026 14:37:41 -0400 Subject: [PATCH 4/8] added package --- man/agcounts-package.Rd | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/man/agcounts-package.Rd b/man/agcounts-package.Rd index 324946e..67ab663 100644 --- a/man/agcounts-package.Rd +++ b/man/agcounts-package.Rd @@ -5,11 +5,7 @@ \alias{agcounts-package} \title{agcounts: Calculate 'ActiGraph' Counts from Accelerometer Data} \description{ -Calculate 'ActiGraph' counts from the X, Y, and Z axes of a triaxial - accelerometer. This work was inspired by Neishabouri et al. who published the - article "Quantification of Acceleration as Activity Counts in 'ActiGraph' Wearables" - on February 24, 2022. The link to the article (\url{https://pubmed.ncbi.nlm.nih.gov/35831446}) - and 'python' implementation of this code (\url{https://github.com/actigraph/agcounts}). +Calculate 'ActiGraph' counts from the X, Y, and Z axes of a triaxial accelerometer. This work was inspired by Neishabouri et al. who published the article "Quantification of Acceleration as Activity Counts in 'ActiGraph' Wearables" on February 24, 2022. The link to the article (\url{https://pubmed.ncbi.nlm.nih.gov/35831446}) and 'python' implementation of this code (\url{https://github.com/actigraph/agcounts}). } \seealso{ Useful links: @@ -22,12 +18,18 @@ Useful links: \author{ \strong{Maintainer}: Brian C. Helsel \email{bhelsel@kumc.edu} +Authors: +\itemize{ + \item Brian C. Helsel \email{bhelsel@kumc.edu} +} + Other contributors: \itemize{ \item Paul R. Hibbing [contributor] \item Robert N. Montgomery [contributor] \item Eric D. Vidoni [contributor] \item Jonathan Clutton [contributor] + \item John Muschelli [contributor] \item University of Kansas [copyright holder] } From 17db95d6320fd5b3fa20d145bce6a84a986a7b33 Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Wed, 20 May 2026 15:12:28 -0400 Subject: [PATCH 5/8] added cpp14 --- DESCRIPTION | 1 + src/Makevars | 1 + src/Makevars.win | 1 + src/gcalibrate.cpp | 2 +- src/resample_helpers.cpp | 3 +-- 5 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 src/Makevars create mode 100644 src/Makevars.win diff --git a/DESCRIPTION b/DESCRIPTION index 7472a52..eeb3853 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -54,3 +54,4 @@ LinkingTo: RcppArmadillo URL: https://github.com/bhelsel/agcounts BugReports: https://github.com/bhelsel/agcounts/issues +SystemRequirements: C++14 diff --git a/src/Makevars b/src/Makevars new file mode 100644 index 0000000..f684e9a --- /dev/null +++ b/src/Makevars @@ -0,0 +1 @@ +CXX_STD = CXX14 diff --git a/src/Makevars.win b/src/Makevars.win new file mode 100644 index 0000000..f684e9a --- /dev/null +++ b/src/Makevars.win @@ -0,0 +1 @@ +CXX_STD = CXX14 diff --git a/src/gcalibrate.cpp b/src/gcalibrate.cpp index f23e65f..27579c3 100644 --- a/src/gcalibrate.cpp +++ b/src/gcalibrate.cpp @@ -1,4 +1,4 @@ -// [[Rcpp::plugins(cpp11)]] +// [[Rcpp::plugins(cpp14)]] #include #include #include diff --git a/src/resample_helpers.cpp b/src/resample_helpers.cpp index b48a8bf..3b78c31 100644 --- a/src/resample_helpers.cpp +++ b/src/resample_helpers.cpp @@ -1,4 +1,4 @@ -// [[Rcpp::plugins(cpp11)]] +// [[Rcpp::plugins(cpp14)]] #include using namespace Rcpp; @@ -25,4 +25,3 @@ NumericMatrix upsampleC(NumericMatrix X, double b_fp) { } return out; } - From 5fb67a4ea7fbeda59cfebfa0721e2cd8eab4c90f Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Wed, 20 May 2026 18:04:51 -0400 Subject: [PATCH 6/8] added fixes for pygt3x_0.7.1 --- .Rbuildignore | 4 +++- .gitignore | 3 ++- R/agread.R | 18 +++++++++++++++++- tests/testthat/test_agread.R | 7 ++++++- tests/testthat/test_shinyServer.R | 7 ++++++- 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index fb50e23..2a534ae 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -7,4 +7,6 @@ ^README\.Rmd$ ^tests/testthat/test_gcalibrateC\.R$ ^man/figures -.vscode/ \ No newline at end of file +.vscode/ +^\.positai$ +^\.claude$ diff --git a/.gitignore b/.gitignore index ebb9f0a..c8ffc24 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ .RData .Ruserdata .DS_Store -.vscode/ \ No newline at end of file +.vscode/ +.positai diff --git a/R/agread.R b/R/agread.R index 0aefe17..20c46bf 100644 --- a/R/agread.R +++ b/R/agread.R @@ -37,6 +37,17 @@ agread <- function(path, parser = c("pygt3x", "GGIR", "read.gt3x"), tz = "UTC", ) } +pygt3x_module_version = function() { + if (!reticulate::py_available(initialize = TRUE)) { + return(NA) + } + if (!reticulate::py_module_available("pygt3x")) { + return(NA) + } + pkgs = reticulate::py_list_packages() + package_version(pkgs[pkgs$package == "pygt3x", "version"]) +} + .pygt3xReader <- function(path, tz = "UTC", verbose = FALSE, ...){ reader <- NULL if(!reticulate::py_module_available("pygt3x")) stop('Python module "pygt3x" not found.') @@ -49,12 +60,17 @@ agread <- function(path, parser = c("pygt3x", "GGIR", "read.gt3x"), tz = "UTC", # Import Classes FileReader <- Reader$FileReader to_pandas <- FileReader$to_pandas + py_module_version = pygt3x_module_version() + cn = c("time", "X", "Y", "Z") + if (py_module_version >= package_version("0.7.1")) { + cn = c(cn, "IdleSleepMode") + } # Read and calibrate data with(FileReader(path) %as% reader, { raw = to_pandas(reader) raw = reset_index(raw)}) # Return Data - colnames(raw) <- c("time", "X", "Y", "Z") + colnames(raw) <- cn raw$time <- as.POSIXct(raw$time, origin = "1970-01-01 00:00:00", tz=tz) meta <- read.gt3x::parse_gt3x_info(path, tz = tz) attr(raw, "start_time") <- meta$`Start Date` %>% lubridate::force_tz(tz) diff --git a/tests/testthat/test_agread.R b/tests/testthat/test_agread.R index e0ee9a3..994647e 100644 --- a/tests/testthat/test_agread.R +++ b/tests/testthat/test_agread.R @@ -5,7 +5,12 @@ testthat::test_that("Check that data can be read into agcounts using pygt3x", { file <- system.file("extdata/example.gt3x", package = "agcounts") pygt3x <- agread(path = file, parser = "pygt3x", verbose = FALSE) expect_equal(nrow(pygt3x), 18000) - expect_equal(ncol(pygt3x), 4) + py_module_version = agcounts:::pygt3x_module_version() + if (py_module_version >= package_version("0.7.1")) { + expect_equal(ncol(pygt3x), 4) + } else { + expect_equal(ncol(pygt3x), 5) + } }) diff --git a/tests/testthat/test_shinyServer.R b/tests/testthat/test_shinyServer.R index 5b71e7f..28ceb2d 100644 --- a/tests/testthat/test_shinyServer.R +++ b/tests/testthat/test_shinyServer.R @@ -18,7 +18,12 @@ testthat::test_that("Shiny app rawDataModuleServer loads raw acceleration data", testthat::compare(input$parser, "pygt3x") # Test the Calibrated Data - testthat::expect_equal(ncol(calibratedData()), 5) + py_module_version = agcounts:::pygt3x_module_version() + if (py_module_version >= package_version("0.7.1")) { + testthat::expect_equal(ncol(calibratedData()), 6L) + } else { + testthat::expect_equal(ncol(calibratedData()), 5L) + } testthat::expect_equal(nrow(calibratedData()), 18000) testthat::compare(mean(calibratedData()$X), 0.9727254, tolerance = 1e-7) testthat::compare(mean(calibratedData()$Y), 0.6042353, tolerance = 1e-7) From ad556a35fb8b086b8f387a70e08e966668af15fb Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Wed, 20 May 2026 20:31:45 -0400 Subject: [PATCH 7/8] updated shinyUI --- tests/testthat/_snaps/shinyUI.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testthat/_snaps/shinyUI.md b/tests/testthat/_snaps/shinyUI.md index 4973d06..c7244c9 100644 --- a/tests/testthat/_snaps/shinyUI.md +++ b/tests/testthat/_snaps/shinyUI.md @@ -59,7 +59,7 @@
Plot Settings for Raw Data
- +
@@ -136,7 +136,7 @@
- +
@@ -208,7 +208,7 @@
- +
From e7fa30425e0dca8cdefb2d3e03c9413ba2813754 Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Wed, 20 May 2026 20:41:28 -0400 Subject: [PATCH 8/8] bug for >= vs. < for package version --- tests/testthat/test_agread.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test_agread.R b/tests/testthat/test_agread.R index 994647e..0121f4e 100644 --- a/tests/testthat/test_agread.R +++ b/tests/testthat/test_agread.R @@ -7,9 +7,9 @@ testthat::test_that("Check that data can be read into agcounts using pygt3x", { expect_equal(nrow(pygt3x), 18000) py_module_version = agcounts:::pygt3x_module_version() if (py_module_version >= package_version("0.7.1")) { - expect_equal(ncol(pygt3x), 4) + expect_equal(ncol(pygt3x), 5L) } else { - expect_equal(ncol(pygt3x), 5) + expect_equal(ncol(pygt3x), 4L) } })