-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add external parser to read_gt3x as a wrapper around the read.gt3x me…
…thod
- Loading branch information
1 parent
c1d8923
commit 8d0a814
Showing
5 changed files
with
86 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
external_parser <- function(file, tz, verbose, ...) { | ||
|
||
read.gt3x::read.gt3x(file, verbose, asDataFrame = TRUE, ...) %>% | ||
dplyr::rename( | ||
"Timestamp" = "time", "Accelerometer_X" = "X", | ||
"Accelerometer_Y" = "Y", "Accelerometer_Z" = "Z" | ||
) %T>% | ||
{stopifnot(exists("Timestamp", .))} %>% | ||
within({Timestamp = lubridate::force_tz(Timestamp, tz)}) %>% | ||
external_restructure(.) | ||
|
||
} | ||
|
||
external_restructure <- function(AG) { | ||
|
||
info <- | ||
attributes(AG) %>% | ||
{.[setdiff(names(.), c("names", "row.names", "class"))]} %>% | ||
c(stringsAsFactors = FALSE) %>% | ||
do.call(data.frame, .) %>% | ||
stats::setNames(., gsub("^header\\.", "", names(.))) %>% | ||
stats::setNames(., gsub("\\.+", "_", names(.))) %>% | ||
.[ ,!duplicated(tolower(names(.)))] %>% | ||
structure(., row.names = 1:nrow(.)) | ||
|
||
attributes(AG) %<>% .[c("names", "row.names", "class")] | ||
|
||
structure(AG, class = c("RAW", "data.frame")) %>% | ||
list(info = info, RAW = .) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.