read.gt3x: Read GT3X

View source: R/readGT3X.R

read.gt3xR Documentation

Read GT3X

Description

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.

Usage

read.gt3x(
  path,
  verbose = FALSE,
  asDataFrame = FALSE,
  imputeZeroes = FALSE,
  flag_idle_sleep = FALSE,
  cleanup = FALSE,
  ...,
  add_light = FALSE
)

Arguments

path

Path to gt3x folder

verbose

print diagnostic messages

asDataFrame

convert to an activity_df, see as.data.frame.activity

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 imputeZeroes = TRUE, this finds where all 3 axes are zero.

cleanup

should any unzipped files be deleted?

...

additional arguments to pass to parseGT3X C++ code, e.g. batch-loading options as now documented in vignette "Batch loading a gt3x file"

add_light

add light data to the data.frame if data exists in the GT3X

Value

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.

Note

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.

See Also

Other gt3x-parsers: as.data.frame.activity(), parse_gt3x_info(), print.gt3x_info()

Examples


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)

read.gt3x documentation built on June 30, 2022, 9:06 a.m.