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

Speed up POSIX calls in part 6 that were recently revised to facilitate backward compatibility with older R versions #1264

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
- Part 6 and new visual report: Fix bug related to determining the combination of thresholds to use for the
visual report and for part 6 analyses when there are several options and
part6_threshold_combi is NULL. #1260


- Part 6: Revise fix to #1181 and #1245 in 3.1-11 as it slowed down part 6 substantially. #1263

# CHANGES IN GGIR VERSION 3.1-11

- Part 2:
Expand Down Expand Up @@ -40,7 +42,7 @@ with only 1 valid day, these were previously skipped. #1246
- Change extraction of imputation code from sleep diary, which is now assumed to
correspond to preceding night. #1251

- Part 1, 5 and 6: Update code to be backward compatible with R 4.2.0
- Part 1, 5 and 6: Update code to be backward compatible with R 4.2.0 #1181 and #1245

- Part 5: Default values for parameters `do.sibreport` and `save_ms5rawlevels` changed
to TRUE, for `save_ms5raw_format` changed to "RData" in order to ease generating visual
Expand Down
16 changes: 7 additions & 9 deletions R/g.part6.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ 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"]],
origin = "1970-01-01")
mdat$time = mdat$timestamp = .POSIXct(mdat$timenum,
tz = params_general[["desiredtz"]])
return(mdat)
}
mdat = imputeTimeGaps(mdat, epochSize)
Expand Down Expand Up @@ -240,8 +239,7 @@ 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"]],
origin = "1970-01-01")
starttime = .POSIXct(ts$time[1], tz = params_general[["desiredtz"]])
summary[fi] = format(starttime)
s_names[fi] = "starttime"
fi = fi + 1
Expand Down Expand Up @@ -294,10 +292,10 @@ 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"]], origin = "1970-01-01"))
sec = tempp$sec
min = tempp$min
hour = tempp$hour
tempp = .POSIXct(acc4cos$time, tz = params_general[["desiredtz"]])
sec = data.table::second(tempp)
min = data.table::minute(tempp)
hour = data.table::hour(tempp)
if (params_general[["dayborder"]] == 0) {
nightsi = which(sec == 0 & min == 0 & hour == 0)
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_part6.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
library(GGIR)
context("g.part6")

test_that("Part 6 with household co-analysis", {
test_that("Part 6 can run household co-analysis and Circadian Rhythm analysis", {

# Create test files for household co-analysis
metadatadir = "./output_testpart6"
Expand Down
Loading