Exports epoch-level sleep data from a withings_sleep object into formats
compatible with external analysis tools like GGIR.
Usage
reformat.withings_sleep(x, type = c("ggir"), ...)Arguments
- x
A
withings_sleepobject created bywithings_sleep- type
Character string specifying output format. Currently supported:
- "ggir"
GGIR-compatible CSV format with columns: id, timestamp (ISO8601), acc
- ...
Additional arguments (currently unused, reserved for future formats)
Value
A data frame in the requested format:
- GGIR format
-
id: Sleep session identifiertimestamp: ISO8601 formatted timestamp (e.g., "2024-01-01T00:00:00Z")acc: Acceleration proxy (usesmvt_scorefrom epoch data if available)
Details
GGIR Format Details:
The GGIR package expects externally-derived epoch data in a specific CSV format. This function converts Withings epoch data to meet those requirements:
Timestamps are converted from Unix timestamps to ISO8601 format in UTC
Movement score (
mvt_score) is used as a proxy for accelerationID column is automatically detected (tries w_id, sleep_id, then id)
The resulting data can be used with GGIR's part 1 for sleep analysis and Sleep Regularity Index (SRI) calculation.
See also
withings_sleep for creating the sleep object
Examples
if (FALSE) { # \dontrun{
# Create withings_sleep object
wsleep <- withings_sleep(summary, epoch)
# Export to GGIR format
ggir_data <- wsleep$reformat(type = "ggir")
# Save for use with GGIR
write.csv(ggir_data, "withings_for_ggir.csv", row.names = FALSE)
# Use with GGIR package
library(GGIR)
GGIR::g.part1(
datadir = ".",
outputdir = "output",
f0 = 1, f1 = 1,
overwrite = TRUE,
externalsleepdata = "withings_for_ggir.csv"
)
} # }
