Skip to content

Commit

Permalink
Merge pull request #626 from wadpac/issue619_ggirread
Browse files Browse the repository at this point in the history
Integrate GGIRread and deprecated selectdaysfile functionality
  • Loading branch information
vincentvanhees authored Sep 2, 2022
2 parents 214d774 + 1c05543 commit 5a3402d
Show file tree
Hide file tree
Showing 63 changed files with 484 additions and 2,090 deletions.
18 changes: 2 additions & 16 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,10 @@ authors:
affiliation: "Activinsights Ltd."
family-names: Fang
given-names: Zhou
-
affiliation: "University of Leicester"
family-names: Mirkes
given-names: Evgeny
orcid: "https://orcid.org/0000-0003-1474-1734"
-
affiliation: "University College London"
family-names: Heywood
given-names: Joe
-
affiliation: "MRC Epidemiology Unit"
family-names: Zhao
given-names: "Jing Hua"
orcid: "https://orcid.org/0000-0003-4930-3582"
-
affiliation: "Polytechnical University of Catalonia"
family-names: Joan
Expand All @@ -44,10 +34,6 @@ authors:
affiliation: "Shimmer Ltd"
family-names: Patterson
given-names: "Matt"
-
affiliation: "Axivity Ltd"
family-names: Jackson
given-names: "Dan"
-
affiliation: Inserm
family-names: Chen
Expand All @@ -57,7 +43,7 @@ authors:
family-names: Manasa
given-names: "Yerramalla"
cff-version: "1.0.3"
date-released: 2022-09-01
date-released: 2022-09-02
doi: "10.5281/zenodo.1051064"
keywords:
- "activity tracker"
Expand All @@ -69,5 +55,5 @@ license: "LGPL-2.0-only"
message: "If you use this software, please cite it using these metadata."
repository-code: "https://github.com/wadpac/GGIR"
title: GGIR
version: "2.7-5"
version: "2.7-6"
...
13 changes: 4 additions & 9 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
Package: GGIR
Type: Package
Title: Raw Accelerometer Data Analysis
Version: 2.7-5
Date: 2022-09-01
Version: 2.7-6
Date: 2022-09-02
Authors@R: c(person("Vincent T","van Hees",role=c("aut","cre"),
email="[email protected]"),
person("Jairo H","Migueles",role="aut"),
person("Severine","Sabia",role="ctb"),
person("Matthew R","Patterson",role="ctb"),
person("Zhou","Fang",role="ctb"),
person("Jing Hua","Zhao",role="ctb"),
person("Joe","Heywood",role="ctb"),
person("Evgeny","Mirkes",role="ctb"),
person("Joan","Capdevila Pujol",role="ctb"),
person("Dan","Jackson",role="ctb"),
person("Lena","Kushleyeva",role="ctb"),
person("Mathilde","Chen",role="ctb"),
person("Manasa","Yerramalla",role="ctb"),
Expand All @@ -30,9 +27,7 @@ URL: https://github.com/wadpac/GGIR/, https://groups.google.com/forum/#!forum/Rp
BugReports: https://github.com/wadpac/GGIR/issues
License: LGPL (>= 2.0, < 3) | file LICENSE
Suggests: testthat, covr, knitr, rmarkdown
Imports: data.table, Rcpp (>= 0.12.10), foreach, doParallel, signal, zoo, GENEAread, tuneR, unisensR, ineq, read.gt3x, activityCounts, ActCR, methods
Imports: data.table, foreach, doParallel, signal, zoo, GENEAread, tuneR, unisensR, ineq, read.gt3x, activityCounts, ActCR, methods, GGIRread
Depends: stats, utils, R (>= 3.5.0)
NeedsCompilation: yes
LinkingTo: Rcpp
VignetteBuilder: knitr
ByteCompile: yes

10 changes: 3 additions & 7 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ export(g.analyse, g.calibrate,
chartime2iso8601, g.abr.day.names,
g.applymetrics, g.create.sp.mat, g.detecmidnight,
g.dotorcomma, g.downsample,
getFirstTimestamp, getStartEndNumeric,
getStartEnd, g.extractheadervars,
g.getidfromheaderobject, g.getM5L5,
getFirstTimestamp, g.extractheadervars,
g.getM5L5,
g.getstarttime, g.loadlog,
g.plot5, g.readaccfile,
g.report.part2, g.report.part4,
g.report.part5, g.sib.det,
g.sib.plot, g.wavread,
g.weardec, isfilelist,
iso8601chartime2POSIX, is_this_a_dst_night,
POSIXtime2iso8601, numUnpack,
resample, is.ISO8601,
POSIXtime2iso8601, is.ISO8601,
updateBlocksize, g.IVIS,
createConfigFile, identify_levels,
g.sib.sum, datadir2fnames,
Expand Down Expand Up @@ -54,5 +52,3 @@ importFrom("stats", "aggregate.data.frame", "weighted.mean",
import(data.table)
importFrom("methods", "is")
importFrom("utils", "available.packages", "packageVersion")
useDynLib(GGIR, .registration = TRUE)
importFrom(Rcpp, sourceCpp)
11 changes: 5 additions & 6 deletions R/GGIR.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,9 @@ GGIR = function(mode = 1:5, datadir = c(), outputdir = c(),
# Print GGIR header to console
GGIRversion = ""
SI = sessionInfo()
try(expr = {GGIRversion = SI$loadedOnly$GGIR$Version}, silent = TRUE)
if (length(GGIRversion) == 0) {
try(expr = {GGIRversion = SI$otherPkgs$GGIR$Version}, silent = TRUE)
}
GGIRversion = SI$otherPkgs$GGIR$Version
if (length(GGIRversion) == 0) GGIRversion = "could not extract version"
GGIRversion = paste0(" ",GGIRversion)
# GGIRversion = paste0(" ",GGIRversion)
rm(SI)
cat(paste0("\n GGIR version: ",GGIRversion,"\n"))
cat("\n Do not forget to cite GGIR in your publications via a version number and\n")
Expand Down Expand Up @@ -206,9 +203,11 @@ GGIR = function(mode = 1:5, datadir = c(), outputdir = c(),
"dopart4", "dopart5", "fnames", "useRDA", "metadatadir", "ci", "config",
"configfile", "filelist", "outputfoldername", "numi", "logi",
"conv2logical", "conv2num", "SI", "params", "argNames", "dupArgNames",
"print_console_header", "configfile_csv", "myfun", "ex", "dir2fn", "fnamesfull") == FALSE)]
"print_console_header", "configfile_csv", "myfun", "ex", "dir2fn", "fnamesfull",
"GGIRversion") == FALSE)]
config.parameters = mget(LS)
config.matrix = as.data.frame(createConfigFile(config.parameters))
config.matrix$context[which(config.matrix$context == "")] = "not applicable"
if (dir.exists(metadatadir)) {
write.csv(config.matrix, file = paste0(metadatadir, "/config.csv"), row.names = FALSE)
} else {
Expand Down
11 changes: 0 additions & 11 deletions R/RcppExports.R

This file was deleted.

2 changes: 1 addition & 1 deletion R/applyExtFunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ applyExtFunction = function(data, myfun, sf, ws3,interpolationType=1) {
# at the moment the function is designed for reading the r3 acceleration channels only,
# because that is the situation of the use-case we had.
rawLast = nrow(rawAccel)
accelRes = resample(rawAccel, rawTime, timeRes, rawLast,
accelRes = GGIRread::resample(rawAccel, rawTime, timeRes, rawLast,
type=interpolationType) # this is now the resampled acceleration data
return(accelRes)
}
Expand Down
10 changes: 8 additions & 2 deletions R/check_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ check_params = function(params_sleep = c(), params_metrics = c(),
"rmc.unit.temp", "rmc.unit.time", "rmc.format.time",
"rmc.origin", "rmc.desiredtz", "rmc.headername.sf",
"rmc.headername.sn", "rmc.headername.recordingid",
"rmc.header.structure")
"rmc.header.structure", "loadGENEActiv")
if (is.logical(params_rawdata[["rmc.noise"]])) {
# Older config files used this, so overwrite with NULL value
params_rawdata[["rmc.noise"]] = c()
Expand Down Expand Up @@ -98,7 +98,7 @@ check_params = function(params_sleep = c(), params_metrics = c(),
numeric_params = c("includedaycrit", "ndayswindow", "strategy", "maxdur", "hrs.del.start",
"hrs.del.end", "includedaycrit.part5", "minimum_MM_length.part5", "includenightcrit", "max_calendar_days")
boolean_params = c("excludefirstlast.part5", "do.imp", "excludefirstlast", "excludefirst.part4", "excludelast.part4")
character_params = c("selectdaysfile", "data_cleaning_file", "TimeSegments2ZeroFile")
character_params = c("data_cleaning_file", "TimeSegments2ZeroFile")
check_class("cleaning", params = params_cleaning, parnames = numeric_params, parclass = "numeric")
check_class("cleaning", params = params_cleaning, parnames = boolean_params, parclass = "boolean")
check_class("cleaning", params = params_cleaning, parnames = character_params, parclass = "character")
Expand All @@ -124,6 +124,12 @@ check_params = function(params_sleep = c(), params_metrics = c(),

#-----------------------------------------------------------------------------------
# Check value combinations and apply corrections if not logical
if (length(params_rawdata) > 0) {
if (params_rawdata[["loadGENEActiv"]] == "GENEAread") {
warning(paste0("\nYou asked GGIR to use package GENEAread instead of GGIRread for reading GENEActiv .bin files.",
" Note that this option will be deprecated in the next CRAN release."))
}
}
if (length(params_metrics) > 0 & length(params_sleep) > 0) {
if (length(params_sleep[["def.noc.sleep"]]) != 2) {
if (params_sleep[["HASPT.algo"]] != "HorAngle") {
Expand Down
22 changes: 16 additions & 6 deletions R/createConfigFile.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,24 @@ createConfigFile = function(config.parameters = c()) {
}
}
SI = sessionInfo()
GGIRversion = ""
try(expr = {GGIRversion = SI$loadedOnly$GGIR$Version}, silent = TRUE)
if (length(GGIRversion) == 0) {
try(expr = {GGIRversion = SI$otherPkgs$GGIR$Version}, silent = TRUE)
GGIRread_version = GGIRversion = ""

if ("GGIR" %in% names(SI$otherPkgs)) {
GGIRversion = SI$otherPkgs$GGIR$Version
} else if ("GGIR" %in% names(SI$loadedOnly)) {
GGIRversion = SI$loadedOnly$GGIR$Version
}
if ("GGIRread" %in% names(SI$otherPkgs)) {
GGIRread_version = SI$otherPkgs$GGIRread$Version
} else if ("GGIRread" %in% names(SI$loadedOnly)) {
GGIRread_version = SI$loadedOnly$GGIRread$Version
}
if (length(GGIRversion) == 0) GGIRversion = "Could not retrieve GGIR version"
out[nrow(out) - 1,] = c("GGIRversion", GGIRversion, " not applicable")
out[nrow(out),] = c("R_version", SI$R.version$version.string, " not applicable")
if (length(GGIRread_version) == 0) GGIRread_version = "Could not retrieve GGIRread version"

out[nrow(out) - 2,] = c("GGIRread_version", GGIRread_version, "not applicable")
out[nrow(out) - 1,] = c("GGIRversion", GGIRversion, "not applicable")
out[nrow(out),] = c("R_version", SI$R.version$version.string, "not applicable")
out = out[which(!is.na(out[,1])),]
out = as.data.frame(out, stringsAsFactors = TRUE)
row.names(out) <- NULL
Expand Down
2 changes: 1 addition & 1 deletion R/extract_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ extract_params = function(params_sleep = c(), params_metrics = c(),
"config_file_in_outputdir", "imputeTimegaps",
"argNames", "dupArgNames","do.sgAccEN", "do.sgAnglex",
"do.sgAngley", "do.sgAnglez", "frag.classes.spt", "i",
"isna", "tmp", "vecchar", "dupi")
"isna", "tmp", "vecchar", "dupi", "GGIRread_version")
# Find argument in the various parameter objects
if (newValue[1] != "notfound" & varName %in% ArgNames2Ignore == FALSE) {
if (varName %in% names(params_general)) {
Expand Down
17 changes: 6 additions & 11 deletions R/g.analyse.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
g.analyse = function(I, C, M, IMP, params_247 = c(), params_phyact = c(),
quantiletype = 7, includedaycrit = 16,
idloc = 1, snloc = 1, selectdaysfile = c(),
dayborder = 0, desiredtz = "", myfun = c(), acc.metric = c(), ...) {
idloc = 1, snloc = 1, dayborder = 0, desiredtz = "",
myfun = c(), acc.metric = c(), ...) {

#get input variables
input = list(...)
expectedArgs = c("I", "C", "M", "IMP", "params_247", "params_phyact",
"quantiletype", "includedaycrit",
"idloc", "snloc", "selectdaysfile", "dayborder",
"idloc", "snloc", "dayborder",
"desiredtz", "myfun")
if (any(names(input) %in% expectedArgs == FALSE) |
any(!unlist(lapply(expectedArgs, FUN = exists)))) {
Expand Down Expand Up @@ -252,7 +252,7 @@ g.analyse = function(I, C, M, IMP, params_247 = c(), params_phyact = c(),
#--------------------------------------------------------------
# Analysis per day
if (doperday == TRUE) {
output_perday = g.analyse.perday(selectdaysfile = selectdaysfile, ndays = ndays,
output_perday = g.analyse.perday(ndays = ndays,
firstmidnighti = firstmidnighti, time = time,
nfeatures = nfeatures, midnightsi = midnightsi,
metashort = metashort, averageday = averageday,
Expand Down Expand Up @@ -339,11 +339,6 @@ g.analyse = function(I, C, M, IMP, params_247 = c(), params_phyact = c(),
} else {
cosinor_ts = c()
}
if (length(selectdaysfile) > 0) {
windowsummary = data.frame(windowsummary,stringsAsFactors = FALSE) # addition for Millenium cohort
names(windowsummary) = ws_names
invisible(list(summary = filesummary, daysummary = daysummary, windowsummary = windowsummary, cosinor_ts = cosinor_ts))
} else {
invisible(list(summary = filesummary, daysummary = daysummary, cosinor_ts = cosinor_ts))
}
invisible(list(summary = filesummary, daysummary = daysummary, cosinor_ts = cosinor_ts))

}
Loading

0 comments on commit 5a3402d

Please sign in to comment.