read.gt3x | R Documentation |
Read activity samples from a GT3X file as a matrix.
Please note that all timestamps are in local time (of the device)
even though they are represented as POSIXct
with GMT timezone.
read.gt3x( path, verbose = FALSE, asDataFrame = FALSE, imputeZeroes = FALSE, flag_idle_sleep = FALSE, cleanup = FALSE, ..., add_light = FALSE )
path |
Path to gt3x folder |
verbose |
print diagnostic messages |
asDataFrame |
convert to an |
imputeZeroes |
Impute zeros in case there are missingness? Default is FALSE, in which case the time series will be incomplete in case there is missingness. |
flag_idle_sleep |
flag idle sleep mode. If |
cleanup |
should any unzipped files be deleted? |
... |
additional arguments to pass to |
add_light |
add light data to the |
A numeric matrix with 3 columns (X, Y, Z) and the following attributes:
start_time
: Start time from info file in POSIXct
format.
subject_name
: Subject name from info file
time_zone
: Time zone from info file
missingness
: Named integer vector. Names are POSIXct
timestamps and values are the number of missing values.
The timestamps in the .gt3x data format are saved in .NET format, which is
nanoseconds in local time since 0001-01-01.
This is a bit tricky to parse into an R datetime format. DateTimes are
therefore represented as POSIXct
format with the
'GMT' timezone attribute, which is false; the datetime actually
represents local time.
Other gt3x-parsers:
as.data.frame.activity()
,
parse_gt3x_info()
,
print.gt3x_info()
gt3xfile <- system.file( "extdata", "TAS1H30182785_2019-09-17.gt3x", package = "read.gt3x") is_gt3x(gt3xfile) have_log_and_info(gt3xfile, verbose = TRUE) x <- read.gt3x(gt3xfile, imputeZeroes = FALSE, asDataFrame = FALSE, verbose = TRUE) attr(x, "features") df2 <- as.data.frame(x, verbose = TRUE) attr(df2, "features") head(df2) rm(x); gc(); gc() rm(df2); gc() x <- read.gt3x(gt3xfile, imputeZeroes = TRUE, asDataFrame = TRUE, verbose = TRUE) ## Not run: # first unzip, then read datadir <- gt3x_datapath() gt3xfolders <- unzip.gt3x(datadir) gt3xfile <- gt3xfolders[2] # temporary unzip, read, convert to a data frame gt3xfile <- gt3x_datapath(1) memory.limit() df <- read.gt3x(gt3xfile, asDataFrame = FALSE, verbose = 2) head(df) rm(df); gc(); gc() df <- read.gt3x(gt3xfile, asDataFrame = TRUE, verbose = 2) head(df) ## End(Not run) ## Not run: url <- paste0("https://github.com/THLfi/read.gt3x/", "files/", "3522749/", "GT3X%2B.01.day.gt3x.zip") destfile <- tempfile(fileext = ".zip") dl <- download.file(url, destfile = destfile, mode = "wb") gt3x_file <- unzip(destfile, exdir = tempdir()) gt3x_file <- gt3x_file[!grepl("__MACOSX", gt3x_file)] path <- gt3x_file res <- read.gt3x(path) gz <- R.utils::gzip(path, remove = FALSE, overwrite = FALSE) df2 <- read.gt3x(gz, asDataFrame = FALSE, verbose = 2) head(df2) rm(df2); gc(); gc() ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.