Skip to content

Commit

Permalink
update read_and_process_embrace_plus
Browse files Browse the repository at this point in the history
  • Loading branch information
hypebright committed Apr 24, 2024
1 parent 5b7e63b commit 5d6af8a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
24 changes: 21 additions & 3 deletions R/read_and_process_embrace_plus.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,31 @@
#' @description Reads the raw ZIP file using `read_embrace_plus`,
#' performs analyses with `eda_analysis`.
#' @param zipfile zip file with embrace plus data to be read
#' @param folder A folder with the unzipped files. If this is provided, the zipfile is not used.
#' @param type The type of data contained in the zip file. Either "raw" or "aggregated".
#' @param tz timezone where data were recorded (default system timezone)
#' @return An object with processed data and analyses, object of class 'embrace_plus_analysis'.
#' @rdname read_and_process_embrace_plus
#' @export
read_and_process_embrace_plus <- function(zipfile, tz = Sys.timezone()) {
data <- read_embrace_plus(zipfile, tz)
data <- rbind_embrace_plus(data)
read_and_process_embrace_plus <- function(zipfile = NULL, folder = NULL, type = "raw", tz = Sys.timezone()) {

# Check if zipfile or folder is provided
if (is.null(zipfile) && is.null(folder)) {
cli_abort("Either zipfile or folder must be provided")
}

if (!is.null(zipfile) && !is.null(folder)) {
cli_warning("Only folder will be processed, zipfile will be ignored")
}

if (!is.null(zipfile)) {
data <- read_embrace_plus(zipfile = zipfile, type = type, tz = tz)
data <- rbind_embrace_plus(data)
}

if (!is.null(folder)) {
data <- read_embrace_plus(folder = folder, type = type, tz = tz)
}

if (is.null(data)) {
return(NULL)
Expand Down
2 changes: 1 addition & 1 deletion R/read_embrace_plus.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ create_dataframes <- function(data, type, file, vars = c("x", "y", "z"),
#'
#' @param zipfile A zip file as exported by the instrument. Can be aggregated data, or raw data.
#' @param folder A folder with the unzipped files. If this is provided, the zipfile is not used.
#' @param type The type of data contained in the zip file. Either "raw" or "aggregated".
#' @param type The type of data contained in the zip file or folder. Either "raw" or "aggregated".
#' @param tz The timezone used by the instrument (defaults to user timezone).
#' @examples
#' \dontrun{
Expand Down
11 changes: 10 additions & 1 deletion man/read_and_process_embrace_plus.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/read_embrace_plus.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5d6af8a

Please sign in to comment.