From 6700e5775ff8e94e39922b6fe8f5e35fd215aa0e Mon Sep 17 00:00:00 2001 From: Vincent van Hees Date: Wed, 20 Mar 2024 14:00:53 +0100 Subject: [PATCH 1/3] fixes #20 --- R/mergeGGIR.R | 6 ++++-- inst/NEWS.Rd | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/R/mergeGGIR.R b/R/mergeGGIR.R index 8aca32c..df89f85 100644 --- a/R/mergeGGIR.R +++ b/R/mergeGGIR.R @@ -4,7 +4,7 @@ mergeGGIR = function(GGIRpath, GPSdf, ID, verbose) { # If user by accident specified GGIR output folder then attempt # to update path to specify the ms5.outraw subfolder inside it - if (length(grep(pattern = "ms5.outraw", x = GGIRpath)) != 0) { + if (length(grep(pattern = "ms5.outraw", x = GGIRpath)) == 0) { newGGIRpath = paste0(GGIRpath, "/meta/ms5.outraw") if (dir.exists(newGGIRpath)) { GGIRpath = newGGIRpath @@ -47,7 +47,9 @@ mergeGGIR = function(GGIRpath, GPSdf, ID, verbose) { # Linearly interpolate acceleration GPSdf$GGIR_ACC = GGIRread::resample(raw = as.matrix(G$ACC), rawTime = G$timenum, time = GPSdf$time, stop = nrow(G), type = 1) # Nearest neigbour interpolate other GGIR output columns - col2impute = c("SleepPeriodTime", "invalidepoch", "guider", "window", "class_id") + if ("class_id" %in% colnames(G) == FALSE) stop("GGIR time series misses class_id column") + if ("invalidepoch" %in% colnames(G) == FALSE) stop("GGIR time series misses invalidepoch column") + col2impute = colnames(G)[which(colnames(G) %in% c("SleepPeriodTime", "invalidepoch", "window", "class_id") == TRUE)] GS = as.data.frame(GGIRread::resample(raw = as.matrix(G[, col2impute]), rawTime = G$timenum, time = GPSdf$time, stop = nrow(G), type = 2)) diff --git a/inst/NEWS.Rd b/inst/NEWS.Rd index 4885382..39c0b33 100644 --- a/inst/NEWS.Rd +++ b/inst/NEWS.Rd @@ -1,6 +1,13 @@ \name{NEWS} \title{News for Package \pkg{GGIRread}} \newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}} +\section{Changes in version 0.0.6 (release date:??-??-2024)}{ + \itemize{ + \item Simplify mergeGGIR to no longer expect window column, see #20 + \item Allow mergeGGIR to handle both full path to ms5.outraw folder or + only the GGIR output folder + } +} \section{Changes in version 0.0.5 (release date:05-03-2024)}{ \itemize{ \item More formats for GPS satillitate info now supported, see #12 From f395de7d66de85e3ffdc61d7624e640955a28710 Mon Sep 17 00:00:00 2001 From: Vincent van Hees Date: Wed, 20 Mar 2024 14:34:55 +0100 Subject: [PATCH 2/3] fixes #19 --- .Rbuildignore | 1 + R/deriveTrips.R | 2 +- tests/testthat/test_hbGPS.R | 16 +++++++++------- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 6dddbab..b23d0c6 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -3,3 +3,4 @@ ^\.github prepareNewRelease.R LICENSE +codecov.yml diff --git a/R/deriveTrips.R b/R/deriveTrips.R index 6a7f821..44489cb 100644 --- a/R/deriveTrips.R +++ b/R/deriveTrips.R @@ -48,7 +48,7 @@ deriveTrips = function(df, tz, minTripDur, minTripDist_m) { s1 = as.POSIXct(Segs$time_t1[tripEnd[j]], tz = tz, origin = "1970-01-01") tripInd = which(df$time >= s0 & df$time <= s1) # trip duration in minutes - tripDur = (Segs$time_t1[tripEnd[j]] - Segs$time_t0[tripStart[j]]) + tripDur = diff(as.numeric(range(df$time[c(tripInd, tripInd[length(tripInd)] + 1)]))) tripDist_m = sum(abs(df$distance_m[tripInd])) maxTimeGap = max(df$deltaTime[tripInd]) tripIncl = mean(df$inclination_deg[tripInd]) diff --git a/tests/testthat/test_hbGPS.R b/tests/testthat/test_hbGPS.R index 541603d..99ff1f8 100644 --- a/tests/testthat/test_hbGPS.R +++ b/tests/testthat/test_hbGPS.R @@ -28,9 +28,9 @@ test_that("hbGPS pipeline process file 4 correctly", { return_object = TRUE) expect_equal(nrow(D), 20029) - expect_equal(ncol(D), 44) + expect_equal(ncol(D), 43) - expect_equal(length(unique(D$trip)), 39) + expect_equal(length(unique(D$trip)), 40) expect_equal(mean(D$GGIR_ACC), 26.19259, tolerance = 0.0001) expect_equal(mean(D$snr), 256.9834, tolerance = 0.0001) expect_equal(mean(D$snr_ratio), 78.81412, tolerance = 0.0001) @@ -43,11 +43,13 @@ test_that("hbGPS pipeline process file 4 correctly", { expect_equal(mean(D$bearing_deg), 10.62006, tolerance = 0.00001) expect_equal(mean(D$deltaBearing), 65.73111, tolerance = 0.00001) - expect_equal(mean(D$tripMaxTimegGap), 0.7691348, tolerance = 0.000001) - expect_equal(mean(D$tripEleSpeed_kmh), 0.03796242, tolerance = 0.000001) + expect_equal(mean(D$tripMaxTimegGap), 0.7728793, tolerance = 0.000001) + expect_equal(mean(D$tripEleSpeed_kmh), 0.03658415, tolerance = 0.000001) # Finally a crude global check to see whether anything has changed - expect_equal(sum(rowSums(D[,c(11:15, 17:41)]), na.rm = TRUE), 26828374, tolerance = 0.1) + num_cols = which(unlist(lapply(D, is.numeric), use.names = FALSE) == TRUE) + num_cols = num_cols[num_cols %in% which(colnames(D) == "timenum") == FALSE] + expect_equal(sum(rowSums(D[, num_cols], na.rm = TRUE)), 27142209, tolerance = 0.1) # Check that it also works with a configFile DC = hbGPS(gps_file = gps_file, @@ -59,8 +61,8 @@ test_that("hbGPS pipeline process file 4 correctly", { configFile = system.file("testfiles/config_hbGPS.csv", package = "hbGPS"), return_object = TRUE) expect_equal(nrow(DC), 20029) - expect_equal(ncol(DC), 44) - expect_equal(length(unique(DC$trip)), 39) + expect_equal(ncol(DC), 43) + expect_equal(length(unique(DC$trip)), 40) expect_equal(mean(DC$GGIR_ACC), 26.19259, tolerance = 0.0001) expect_equal(mean(DC$speed_ms), 0.6386111, tolerance = 0.0001) From f1f73d76e8765c5db4b19662a07ba72d621c8b4f Mon Sep 17 00:00:00 2001 From: Vincent van Hees Date: Wed, 20 Mar 2024 14:37:57 +0100 Subject: [PATCH 3/3] increment version number and release data --- DESCRIPTION | 4 ++-- inst/NEWS.Rd | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6fbc7a2..fccb81e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: hbGPS Type: Package Title: Process GPS Data For Human Behaviour Research -Version: 0.0.4 -Date: 2023-09-28 +Version: 0.0.6 +Date: 2024-03-20 Authors@R: c(person("Vincent T","van Hees",role=c("aut","cre"), email="v.vanhees@accelting.com"), person("SDU Denmark", role = c("cph", "fnd"))) diff --git a/inst/NEWS.Rd b/inst/NEWS.Rd index 39c0b33..06a8e15 100644 --- a/inst/NEWS.Rd +++ b/inst/NEWS.Rd @@ -1,7 +1,7 @@ \name{NEWS} \title{News for Package \pkg{GGIRread}} \newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}} -\section{Changes in version 0.0.6 (release date:??-??-2024)}{ +\section{Changes in version 0.0.6 (release date:20-03-2024)}{ \itemize{ \item Simplify mergeGGIR to no longer expect window column, see #20 \item Allow mergeGGIR to handle both full path to ms5.outraw folder or