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: 3 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
^README\.Rmd$
^tests/testthat/test_gcalibrateC\.R$
^man/figures
.vscode/
.vscode/
^\.positai$
^\.claude$
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
.RData
.Ruserdata
.DS_Store
.vscode/
.vscode/
.positai
7 changes: 5 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", 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
Expand All @@ -20,7 +21,6 @@ Depends:
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.1
Imports:
data.table,
gsignal,
Expand Down Expand Up @@ -54,3 +54,6 @@ LinkingTo:
RcppArmadillo
URL: https://github.com/bhelsel/agcounts
BugReports: https://github.com/bhelsel/agcounts/issues
SystemRequirements: C++14
Config/roxygen2/version: 8.0.0

28 changes: 22 additions & 6 deletions R/agread.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,24 @@ 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)
)
}

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.')
Expand All @@ -49,14 +60,19 @@ 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)
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
Expand All @@ -66,7 +82,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
Expand Down
12 changes: 7 additions & 5 deletions man/agcounts-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/Makevars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CXX_STD = CXX14
1 change: 1 addition & 0 deletions src/Makevars.win
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CXX_STD = CXX14
2 changes: 1 addition & 1 deletion src/gcalibrate.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// [[Rcpp::plugins(cpp11)]]
// [[Rcpp::plugins(cpp14)]]
#include <RcppArmadillo.h>
#include <iostream>
#include <vector>
Expand Down
3 changes: 1 addition & 2 deletions src/resample_helpers.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// [[Rcpp::plugins(cpp11)]]
// [[Rcpp::plugins(cpp14)]]
#include <Rcpp.h>
using namespace Rcpp;

Expand All @@ -25,4 +25,3 @@ NumericMatrix upsampleC(NumericMatrix X, double b_fp) {
}
return out;
}

6 changes: 3 additions & 3 deletions tests/testthat/_snaps/shinyUI.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<h5><b>Plot Settings for Raw Data</b></h5>
<div class="form-group shiny-input-container">
<label class="control-label" id="rawDataModule-gt3xPlotColor-label" for="rawDataModule-gt3xPlotColor">Plot Color (accepts color name or hex code)</label>
<input id="rawDataModule-gt3xPlotColor" type="text" class="shiny-input-text form-control" value="#000000"/>
<input id="rawDataModule-gt3xPlotColor" type="text" class="shiny-input-text form-control" value="#000000" data-update-on="change"/>
</div>
<div id="rawDataModule-rangeXraw" class="shiny-html-output"></div>
<div id="rawDataModule-rangeYraw" class="shiny-html-output"></div>
Expand Down Expand Up @@ -136,7 +136,7 @@
</div>
<div class="form-group shiny-input-container">
<label class="control-label" id="countsModule-countsPlotColor-label" for="countsModule-countsPlotColor">Plot Color (accepts color name or hex code)</label>
<input id="countsModule-countsPlotColor" type="text" class="shiny-input-text form-control" value="#000000"/>
<input id="countsModule-countsPlotColor" type="text" class="shiny-input-text form-control" value="#000000" data-update-on="change"/>
</div>
<div id="countsModule-rangeCounts" class="shiny-html-output"></div>
</form>
Expand Down Expand Up @@ -208,7 +208,7 @@
<div id="compareCountsModule-rangeYBlandAltman" class="shiny-html-output"></div>
<div class="form-group shiny-input-container">
<label class="control-label" id="compareCountsModule-agdPlotColor-label" for="compareCountsModule-agdPlotColor">Plot Color (accepts color name or hex code)</label>
<input id="compareCountsModule-agdPlotColor" type="text" class="shiny-input-text form-control" value="#000000"/>
<input id="compareCountsModule-agdPlotColor" type="text" class="shiny-input-text form-control" value="#000000" data-update-on="change"/>
</div>
</form>
</div>
Expand Down
10 changes: 9 additions & 1 deletion tests/testthat/test_agread.R
Original file line number Diff line number Diff line change
Expand Up @@ -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), 5L)
} else {
expect_equal(ncol(pygt3x), 4L)
}
})


Expand All @@ -21,6 +26,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)))
Expand Down
7 changes: 6 additions & 1 deletion tests/testthat/test_shinyServer.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading