Skip to content

Commit 0389a28

Browse files
authored
Merge pull request #52 from PhysicalActivityOpenTools/issue51_classesAsFactor
Issue51 classes as factor
2 parents 5aa4412 + e33b0c6 commit 0389a28

File tree

8 files changed

+18
-8
lines changed

8 files changed

+18
-8
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: actimetric
22
Type: Package
33
Title: Classifies Accelerometer Data Into Physical Activity Types
4-
Version: 0.1.3
4+
Version: 0.1.4
55
Authors@R: c(person("Jairo H","Migueles", role = c("aut","cre"),
66
email = "[email protected]",
77
comment = c(ORCID = "0000-0003-0366-6935")),

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# actimetric 0.1.4
2+
3+
* Time series: stores classes as factor in time series to ease interpretation #51
4+
* Documentation: minor revision of documentation for functions check_classifier and getBout #41
5+
16
# actimetric 0.1.3
27

38
* Calibration: fix minor bug by which calibration procedure was using time column instead of acceleration columns in data #49

R/aggregate_per_date.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ aggregate_per_date = function(tsDir, epoch, classifier, classes,
4242
# format timestamp to ease calculations
4343
ts$timestamp = strptime(paste(ts$date, ts$time), format = "%Y-%m-%d %H:%M:%OS", tz = "")
4444
ts$time = format(ts$timestamp, "%H:%M:%S")
45-
ts$activity = factor(ts$activity, levels = 1:length(classes), labels = classes)
45+
if (is.numeric(ts$activity)) { # ensures compatibility with versions <0.1.4
46+
ts$activity = factor(ts$activity, levels = 1:length(classes), labels = classes)
47+
}
4648
# Day of the week, used for summarizing per day
4749
availableDates = unique(ts$date)
4850
# matrix to store the results

R/check_classifier.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#'
1010
#' @return Character with the definitive classifier
1111
#' @export
12-
#'
13-
#' @examples
1412
#' @author Jairo H. Migueles <[email protected]>
1513
#' check_classifier("Adult wrist Trost")
1614
check_classifier = function(classifier) {

R/classifySleep.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ classifySleep = function(anglez, starttime, classifier, infoClassifier, ts, do.s
7676
}
7777
}
7878
# add nonwear to ts
79+
ts$activity = as.numeric(ts$activity)
7980
nonwear_id = length(classes) + 1
8081
classes = c(classes, "nonwear")
8182
ts$nonwear_orig = ts$nonwear
@@ -128,6 +129,6 @@ classifySleep = function(anglez, starttime, classifier, infoClassifier, ts, do.s
128129
ts$activity[which(ts$sleep_periods == 1)] = sleep_id
129130
}
130131
}
131-
activity = ts$activity
132+
activity = factor(x = ts$activity, levels = 1:length(classes), labels = classes)
132133
return(activity)
133134
}

R/getBout.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#' @param epoch Integer (default = 5) indicating the epoch length in seconds.
1111
#' @param boutmaxgap Integer (default = 1) with maximum consecutive gap length allowed in bout calculation.
1212
#'
13-
#' @return
13+
#' @return Vector with 0's and 1's indicating bout occurrences.
1414
#' @export
1515
#' @references GGIR R Package. doi: 10.1123/jmpb.2018-0063
1616
getBout = function(x, boutduration = 10, boutcriter = 0.8, boutmaxgap = 1, epoch = 5) {

R/runActimetric.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ runActimetric = function(input_directory = NULL, output_directory = NULL, studyn
227227
S = matrix(0,0,4) #dummy variable needed to cope with head-tailing succeeding blocks of data
228228
# ---------------------------------------------------------------------
229229
# Run Pipeline...
230-
nonwear = enmo = agcounts = LFEcounts = tilt = anglez = activity = NULL
230+
nonwear = enmo = agcounts = LFEcounts = tilt = anglez = NULL
231+
activity = factor()
231232
while (isLastBlock == FALSE) {
232233
# 1 - read and extract calibration coefficients
233234
accread = ReadAndCalibrate(file = file, sf = sf, blocksize = blocksize,
@@ -340,7 +341,7 @@ runActimetric = function(input_directory = NULL, output_directory = NULL, studyn
340341
if (!is.null(LFEcounts)) {
341342
if (nrow(LFEcounts) == nrow(ts)) ts = as.data.frame(cbind(ts, LFEcounts))
342343
}
343-
numeric_columns = sapply(ts, mode) == 'numeric'
344+
numeric_columns = sapply(ts, class) == 'numeric'
344345
ts[numeric_columns] = round(ts[numeric_columns], 3)
345346
ts = do.call(data.frame,lapply(ts, function(x) replace(x, is.infinite(x), NA)))
346347
ts[is.na(ts)] = 0

man/getBout.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)