Skip to content

Commit bf355ea

Browse files
committed
make sure do.sleep is TRUE before deriving sleep timestamps
1 parent 59756e0 commit bf355ea

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

R/runActimetric.R

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ runActimetric = function(input_directory = NULL, output_directory = NULL, studyn
239239
S = matrix(0,0,4) #dummy variable needed to cope with head-tailing succeeding blocks of data
240240
# ---------------------------------------------------------------------
241241
# Run Pipeline...
242-
nonwear = enmo = agcounts = LFEcounts = tilt = anglez = NULL
242+
nonwear = enmo = agcounts = LFEcounts = tilt = anglez = anglez_df = NULL
243243
activity = factor()
244244
while (isLastBlock == FALSE) {
245245
# 1 - read and extract calibration coefficients
@@ -431,10 +431,12 @@ runActimetric = function(input_directory = NULL, output_directory = NULL, studyn
431431
ts[is.na(ts)] = 0
432432
# classify sleep and nonwear and add them to ts$activity
433433
if (do.sleep == TRUE | do.nonwear == TRUE) {
434-
# derive timestamp for anglez
435-
ts_sleep = deriveTimestamps(from = recording_starttime, length = length(anglez),
436-
epoch = 5, tz = tz)
437-
anglez_df = data.frame(date = ts_sleep[, 1], time = ts_sleep[, 2], anglez = anglez)
434+
# derive timestamp for anglez if do.sleep == TRUE
435+
if (do.sleep == TRUE) {
436+
ts_sleep = deriveTimestamps(from = recording_starttime, length = length(anglez),
437+
epoch = 5, tz = tz)
438+
anglez_df = data.frame(date = ts_sleep[, 1], time = ts_sleep[, 2], anglez = anglez)
439+
}
438440
activity = classifySleep(anglez = anglez_df, starttime = recording_starttime,
439441
classifier = classifier, infoClassifier = infoClassifier,
440442
ts = ts, do.sleep = do.sleep, do.nonwear = do.nonwear)

0 commit comments

Comments
 (0)