Skip to content
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
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Authors@R: c(person("Vincent T","van Hees",role=c("aut","cre"),
person("Evgeny","Mirkes",role="ctb"),
person("Dan","Jackson",role="ctb"),
person("Jairo H","Migueles",role="ctb"),
person("John","Muschelli",role="ctb"),
person("Medical Research Council UK", role = c("cph", "fnd")),
person("Accelting", role = c("cph", "fnd")))
Maintainer: Vincent T van Hees <v.vanhees@accelting.com>
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Changes in version 1.0.10 (release date:15-07-2026)

- Fix bug in readGENEActiv with `path.expand`. #94 @muschellij2

# Changes in version 1.0.9 (release date:15-07-2026)

- Fix bug in readActiwatchCount. #92
Expand Down
30 changes: 16 additions & 14 deletions R/readGENEActiv.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
readGENEActiv = function(filename, start = 0, end = 0, progress_bar = FALSE,
readGENEActiv = function(filename, start = 0, end = 0, progress_bar = FALSE,
desiredtz = "", configtz = NULL) {

# Extract information from the fileheader
suppressWarnings({fh = readLines(filename, 69)})

SN = gsub(pattern = "Device Unique Serial Code:", replacement = "",
x = fh[grep(pattern = "Device Unique Serial Code", x = fh)[1]])
firmware = gsub(pattern = "Device Firmware Version:", replacement = "",
Expand All @@ -17,30 +17,32 @@ readGENEActiv = function(filename, start = 0, end = 0, progress_bar = FALSE,
# when battery runs out prior to end of recording
starttime = gsub(pattern = "Page Time:", replacement = "",
x = fh[grep(pattern = "Page Time", x = fh)[1]])

tzone = gsub(pattern = "Time Zone:", replacement = "",
x = fh[grep(pattern = "Time Zone", x = fh)[1]])
tzone = as.numeric(unlist(strsplit(tzone, "[:]| "))[2]) * 3600

Handedness = gsub(pattern = "Handedness Code:", replacement = "",
x = fh[grep(pattern = "Handedness Code", x = fh)[1]])
ID = gsub(pattern = "Subject Code:", replacement = "",
x = fh[grep(pattern = "Subject Code", x = fh)[1]])

DeviceLocation = gsub(pattern = "Device Location Code:", replacement = "",
x = fh[grep(pattern = "Device Location Code", x = fh)[1]])

DeviceModel = gsub(pattern = " ", replacement = "",
x = gsub(pattern = "Device Model:", replacement = "",
x = fh[grep(pattern = "Device Model", x = fh)[1]]))

# needed for fix for #94
filename = path.expand(filename)
# Read acceleration, lux and temperature data
rawdata = GENEActivReader(filename = filename,
start = start, end = end,
start = start, end = end,
progress_bar = progress_bar)

rawdata$time = rawdata$time / 1000

# Construct header object
header = list(serial_number = SN,
firmware = firmware,
Expand All @@ -54,12 +56,12 @@ readGENEActiv = function(filename, start = 0, end = 0, progress_bar = FALSE,
RecordingID = ID,
DeviceLocation = DeviceLocation,
DeviceModel = DeviceModel)

s0 = unlist(strsplit(starttime, ":"))
if (length(s0) == 4) {
starttime = paste0(s0[1], ":", s0[2], ":", s0[3], ".", s0[4])
}

# Establish starttime in the correct timezone
if (is.null(configtz)) {
starttime_posix = as.POSIXlt(x = starttime, tz = desiredtz,
Expand All @@ -68,7 +70,7 @@ readGENEActiv = function(filename, start = 0, end = 0, progress_bar = FALSE,
starttime_posix = as.POSIXlt(starttime, tz = configtz,
format = "%Y-%m-%d %H:%M:%OS", origin = "1970-01-01")
}

# Correct timestamps
if (start > 1) {
page_offset = (((start - 1) * 300) / rawdata$info$SampleRate)
Expand All @@ -79,7 +81,7 @@ readGENEActiv = function(filename, start = 0, end = 0, progress_bar = FALSE,
rawdata$time = rawdata$time + abs(rawdata$time[1]) + starttime_num
return(invisible(list(
header = header,
data.out = data.frame(time = rawdata$time,
data.out = data.frame(time = rawdata$time,
x = rawdata$x, y = rawdata$y, z = rawdata$z,
light = rawdata$lux * (Lux/Volts),
temperature = rawdata$temperature,
Expand Down
Loading