Skip to content

Commit 30d87af

Browse files
committed
update cpp exports and version number
1 parent 5d6a202 commit 30d87af

4 files changed

Lines changed: 19 additions & 10 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: GGIRread
22
Type: Package
33
Title: Wearable Accelerometer Data File Readers
4-
Version: 1.0.3
4+
Version: 1.0.4
55
Date: 2025-03-07
66
Authors@R: c(person("Vincent T","van Hees",role=c("aut","cre"),
77
email="v.vanhees@accelting.com"),

R/readParmayMatrix.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ readParmayMatrix = function(bin_file, output = c("all", "sf", "dynrange")[1],
279279
}
280280

281281
# lists to data frames
282-
acc_data = do.call(rbind, acc_readings)
282+
if (any(acc_count > 0) & read_acc) acc_data = do.call(rbind, acc_readings)
283283
if (any(gyro_count > 0) & read_gyro) gyro_data = do.call(rbind, gyro_readings)
284284
if (any(temp_count > 0) & read_temp) temp_data = do.call(rbind, temp_readings)
285285
if (any(heart_count > 0) & read_heart) {
@@ -387,7 +387,7 @@ readParmayMatrix = function(bin_file, output = c("all", "sf", "dynrange")[1],
387387
data = data.frame(time = required_timepoints)
388388

389389
# add sensors if available
390-
if (any(gyro_count > 0) & read_acc) data[, c("acc_x", "acc_y", "acc_z")] = acc_resampled
390+
if (any(acc_count > 0) & read_acc) data[, c("acc_x", "acc_y", "acc_z")] = acc_resampled
391391
if (any(gyro_count > 0) & read_gyro) data[, c("gyro_x", "gyro_y", "gyro_z")] = gyro_resampled
392392
if (any(temp_count > 0) & read_temp) data[, c("bodySurface_temp", "ambient_temp")] = temp_resampled
393393
if (any(heart_count > 0) & read_heart) data[, c("hr_raw", "hr")] = heart_resampled

src/find_matrix_packet_start.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,27 @@ Rcpp::IntegerVector find_matrix_packet_start(std::string file_path, Rcpp::RawVec
1818
std::streamsize bytesRead = file.gcount();
1919
if (bytesRead == 0) break; // Stop if no more bytes read
2020

21+
// Ensure we don't compare signed and unsigned types
22+
size_t search_limit = static_cast<size_t>(std::max(static_cast<std::streamoff>(bytesRead) - pattern_len, static_cast<std::streamoff>(0)));
23+
2124
// Search for pattern in the current buffer
22-
for (size_t i = 0; i <= bytesRead - pattern_len; ++i) {
25+
for (size_t i = 0; i <= search_limit; ++i) {
2326
bool match = true;
24-
for (size_t j = 0; j < pattern_len; ++j) {
27+
for (size_t j = 0; j < static_cast<size_t>(pattern_len); ++j) {
2528
if (buffer[i + j] != pattern[j]) {
2629
match = false;
2730
break;
2831
}
2932
}
3033
if (match) {
31-
indices.push_back(position + i + 1); // Convert to 1-based index
34+
indices.push_back(static_cast<int>(position + static_cast<std::streamoff>(i) + 1)); // Convert to 1-based index
3235
}
3336
}
3437

3538
// Move back the last `pattern_len - 1` bytes for next chunk to prevent missed matches
3639
if (bytesRead >= pattern_len - 1) {
37-
file.seekg(position + bytesRead - (pattern_len - 1));
38-
position += bytesRead - (pattern_len - 1);
40+
file.seekg(position + static_cast<std::streamoff>(bytesRead) - static_cast<std::streamoff>(pattern_len - 1));
41+
position = file.tellg();
3942
} else {
4043
break; // If not enough bytes left, end
4144
}

tests/testthat/test_readParmayMatrix.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ test_that("File including accelerometer and heart rate data at 25Hz", {
1919
expect_equal(BIN$acc_dynrange, 8)
2020
expect_equal(as.numeric(BIN$starttime), BIN$data$time[1])
2121
expect_equal(nrow(BIN$data), 24525)
22-
expect_equal(ncol(BIN$data), 7) # time, x, y, z, hr_raw, hr, remarks
22+
expect_equal(ncol(BIN$data), 5) # time, x, y, z, remarks (no hr because deactivated by default)
2323
expect_equal(nrow(BIN$QClog), 4) # 4 packets in file
2424
expect_true(all(BIN$QClog$checksum_pass))
25+
BIN = readParmayMatrix(bin_file = binfile, desiredtz = "Europe/Berlin", start = 1, end = NULL,
26+
read_heart = TRUE)
27+
expect_equal(ncol(BIN$data), 7) # time, x, y, z, hr_raw, hr, remarks
2528
})
2629

2730
test_that("File including accelerometer, heart rate, and temperature data at 100Hz", {
@@ -31,7 +34,10 @@ test_that("File including accelerometer, heart rate, and temperature data at 100
3134
expect_equal(BIN$acc_dynrange, 8)
3235
expect_equal(as.numeric(BIN$starttime), BIN$data$time[1])
3336
expect_equal(nrow(BIN$data), 39400)
34-
expect_equal(ncol(BIN$data), 9) # time, x, y, z, boyd temp, ambient temp, hr_raw, hr, remarks
37+
expect_equal(ncol(BIN$data), 7) # time, x, y, z, body temp, ambient temp,remarks
3538
expect_equal(nrow(BIN$QClog), 4) # 4 packets in file
3639
expect_true(all(BIN$QClog$checksum_pass))
40+
BIN = readParmayMatrix(bin_file = binfile, desiredtz = "Europe/Berlin", start = 1, end = NULL,
41+
read_heart = TRUE)
42+
expect_equal(ncol(BIN$data), 9) # time, x, y, z, body temp, ambient temp, hr_raw, hr, remarks
3743
})

0 commit comments

Comments
 (0)