Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make backward compatible with R 4.2.0 #1255

Merged
merged 5 commits into from
Jan 22, 2025
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: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: GGIR
Type: Package
Title: Raw Accelerometer Data Analysis
Version: 3.1-10
Date: 2025-01-10
Version: 3.1-11
Date: 2025-01-23
Authors@R: c(person("Vincent T","van Hees",role=c("aut","cre"),
email="v.vanhees@accelting.com"),
person("Jairo H","Migueles",role="aut",
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CHANGES IN GGIR VERSION 3.1-??
# CHANGES IN GGIR VERSION 3.1-11

- Part 2:

Expand All @@ -21,6 +21,10 @@
- Added warning when there are two accelerometer recordings with the same ID.

- Change extraction of imputation code from sleep diary, which is now assumed to correspond to preceding night. This is now also documented. #1251

- Part 1, 5 and 6:

- Update code to be backward compatible with R 4.2.0

# CHANGES IN GGIR VERSION 3.1-10

Expand Down
18 changes: 16 additions & 2 deletions R/g.imputeTimegaps.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,28 @@ g.imputeTimegaps = function(x, sf, k=0.25, impute = TRUE,
x$next_epoch_delay = 0
longEpochDayCut = seq(0, 24 * 60^2, by = longEpochSize)
x$imputation = 0; imp = 0 # keep track of the imputation to organize data later on
Rversion_lt_420 = as.numeric(R.Version()$major) >= 4 && as.numeric(R.Version()$minor) > 2
for (i in gap90i) {
imp = imp + 1
if (Rversion_lt_420) {
time_i = x$time[i]
time_ip1 = x$time[i + 1]
} else {
# Further down data.table is used to extract hour and minute from time stamps
# In R 4.2.0 and earlier numeric time cannot be provided to data.table
# For those older version of R convert timestamp format
# Tz is set to GMT because at this point we do not care about the specific time
# as time is removed at the end of the function, we only use it
# to identify time gaps and their size.
time_i = as.POSIXct(x$time[i], origin = "1970-01-01", tz = "GMT")
time_ip1 = as.POSIXct(x$time[i + 1], origin = "1970-01-01", tz = "GMT")
}
# short epochs to add to fill up to next long epoch cut
seconds = data.table::hour(x$time[i]) * 60^2 + data.table::minute(x$time[i]) * 60 + data.table::second(x$time[i]) + 1
seconds = data.table::hour(time_i) * 60^2 + data.table::minute(time_i) * 60 + data.table::second(time_i) + 1
seconds_from_prevCut = seconds - max(longEpochDayCut[which(longEpochDayCut <= seconds)])
shortEpochs2add_1 = (longEpochSize - seconds_from_prevCut) / shortEpochSize
# short epochs to add after time gap
seconds = data.table::hour(x$time[i + 1]) * 60^2 + data.table::minute(x$time[i + 1]) * 60 + data.table::second(x$time[i + 1]) + 1
seconds = data.table::hour(time_ip1) * 60^2 + data.table::minute(time_ip1) * 60 + data.table::second(time_ip1) + 1
seconds_from_prevCut = seconds - max(longEpochDayCut[which(longEpochDayCut <= seconds)])
shortEpochs2add_2 = (seconds_from_prevCut - 1) / shortEpochSize
# short epochs to add - total
Expand Down
8 changes: 5 additions & 3 deletions R/g.part5.wakesleepwindows.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ g.part5.wakesleepwindows = function(ts, part4_output, desiredtz, nightsi,
# Round seconds to integer number of epoch lengths (needed if cleaningcode = 5).
round_seconds_to_epochSize = function(x, epochSize) {
if (length(as.numeric(unlist(strsplit(x,":")))) == 3) {
xPOSIX = as.POSIXct(x, format = "%H:%M:%S")
xPOSIX_rounded = as.POSIXct(round(as.numeric(xPOSIX) / epochSize) * epochSize)
xPOSIX = as.POSIXct(x, format = "%H:%M:%S", origin = "1970-01-01")
xPOSIX_rounded = as.POSIXct(round(as.numeric(xPOSIX) / epochSize) * epochSize,
origin = "1970-01-01")
x = format(xPOSIX_rounded, format = "%H:%M:%S")
} else {
x = ""
Expand Down Expand Up @@ -67,7 +68,8 @@ g.part5.wakesleepwindows = function(ts, part4_output, desiredtz, nightsi,
w1[k] = paste(tt[3],"-", tt[2], "-", tt[1], " ", as.character(defWA_ts), sep = "")
# if time is beyond 24 then change the date
if (defSO >= 24) {
w0[k] = as.character(as.POSIXlt(w0[k],tz = desiredtz) + (24*3600))
tmp_w0 = as.POSIXlt(w0[k],tz = desiredtz, origin = "1970-01-01")
w0[k] = as.character(tmp_w0 + (24*3600))
}
if (defWA >= 24 |
(part4_output$daysleeper[k] == 1 & defWA < 18)) {
Expand Down
9 changes: 6 additions & 3 deletions R/g.part6.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ g.part6 = function(datadir = c(), metadatadir = c(), f0 = c(), f1 = c(),
mdat$window[invalid] = 9999
mdat$invalid_sleepperiod[invalid] = 100
mdat$invalid_wakinghours[invalid] = 100
mdat$time = mdat$timestamp = as.POSIXct(mdat$timenum, tz = params_general[["desiredtz"]])
mdat$time = mdat$timestamp = as.POSIXct(mdat$timenum,
tz = params_general[["desiredtz"]],
origin = "1970-01-01")
return(mdat)
}
mdat = imputeTimeGaps(mdat, epochSize)
Expand Down Expand Up @@ -238,7 +240,8 @@ g.part6 = function(datadir = c(), metadatadir = c(), f0 = c(), f1 = c(),
summary[fi] = unlist(strsplit(fnames.ms5raw[i], "_"))[1]
s_names[fi] = "ID"
fi = fi + 1
starttime = as.POSIXlt(ts$time[1], tz = params_general[["desiredtz"]])
starttime = as.POSIXlt(ts$time[1], tz = params_general[["desiredtz"]],
origin = "1970-01-01")
summary[fi] = format(starttime)
s_names[fi] = "starttime"
fi = fi + 1
Expand Down Expand Up @@ -291,7 +294,7 @@ g.part6 = function(datadir = c(), metadatadir = c(), f0 = c(), f1 = c(),
threshold = as.numeric(unlist(strsplit( params_phyact[["part6_threshold_combi"]], "_"))[1])

# extract nightsi again
tempp = unclass(as.POSIXlt(acc4cos$time, tz = params_general[["desiredtz"]]))
tempp = unclass(as.POSIXlt(acc4cos$time, tz = params_general[["desiredtz"]], origin = "1970-01-01"))
sec = tempp$sec
min = tempp$min
hour = tempp$hour
Expand Down
4 changes: 2 additions & 2 deletions man/GGIR-package.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
\tabular{ll}{
Package: \tab GGIR\cr
Type: \tab Package\cr
Version: \tab 3.1-10\cr
Date: \tab 2025-01-10\cr
Version: \tab 3.1-11\cr
Date: \tab 2025-01-23\cr
License: \tab Apache License (== 2.0)\cr
Discussion group: \tab https://groups.google.com/forum/#!forum/rpackageggir\cr
}
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test_part6.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ test_that("Part 6 with household co-analysis", {
"day_IN_bts_10_30", "day_LIG_bts_10")

mdat$timenum = mdat$timenum - (5 * 60)
mdat$timestamp = as.POSIXct(mdat$timenum, tz = params_general[["desiredtz"]])
mdat$timestamp = as.POSIXct(mdat$timenum, tz = params_general[["desiredtz"]], origin = "1970-01-01")
filename = "800-900-001_left wrist.bin"
save(mdat, filename, Lnames, file = paste0(dn, "/800-900-001_left wrist.RData"))
mdat$timenum = mdat$timenum + (7 * 60)
mdat$timestamp = as.POSIXct(mdat$timenum, tz = params_general[["desiredtz"]])
mdat$timestamp = as.POSIXct(mdat$timenum, tz = params_general[["desiredtz"]], origin = "1970-01-01")
filename = "800-900-002_left wrist.bin"
save(mdat, filename, Lnames, file = paste0(dn, "/800-900-002_left wrist.RData"))
mdat$timenum = mdat$timenum + (14 * 60)
mdat$timestamp = as.POSIXct(mdat$timenum, tz = params_general[["desiredtz"]])
mdat$timestamp = as.POSIXct(mdat$timenum, tz = params_general[["desiredtz"]], origin = "1970-01-01")
filename = "800-900-003_left wrist.bin"
save(mdat, filename, Lnames, file = paste0(dn, "/800-900-003_left wrist.RData"))
mdat_file3 = mdat
Expand Down
Loading