diff --git a/DESCRIPTION b/DESCRIPTION index 3d1ab4d..de2057b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: wearables Title: Tools to Read and Convert Wearables Data -Version: 0.10.0 -Date: 2024-02-27 +Version: 0.11.0 +Date: 2024-04-18 Authors@R: c( person("Peter", "de Looff", , "peterdelooff@gmail.com", role = c("aut", "cre")), person("Remko", "Duursma", role = "aut"), @@ -14,7 +14,7 @@ Authors@R: c( person("Veerle", "van Leemput", role = "ctb") ) Maintainer: Peter de Looff -Description: Package to read Empatica E4 data, perform several +Description: Package to read Empatica E4, Embrace Plus, and Nowatch data, perform several transformations, perform signal processing and analyses, including batch analyses. License: GPL-2 diff --git a/NAMESPACE b/NAMESPACE index ebd76d1..a173cc8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,7 @@ S3method(print,e4data) export(aggregate_data) export(aggregate_e4_data) export(aggregate_embrace_plus_data) +export(aggregate_nowatch_data) export(as_time) export(as_timeseries) export(batch_analysis) @@ -37,6 +38,7 @@ export(read_and_process_e4) export(read_and_process_embrace_plus) export(read_e4) export(read_embrace_plus) +export(read_nowatch) export(upsample_data_to_8Hz) export(write_processed_e4) import(cli) diff --git a/NEWS.md b/NEWS.md index 55eae71..27800a1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,12 @@ +# wearables 0.11.0 +2024-04-18 + +## New features +* Added new function to read data from Nowatch: `read_nowatch()`. This function will return a list of dataframes with the data from the Nowatch. Both a zipfile and a folder are accepted as input. This function is intended for aggregated data, as the Nowatch does not provide raw data. +* Added reading of aggregated data from Embrace Plus by adding a `type` argument in `read_embrace_plus()`. This argument can be set to `raw` or `aggregated` to read the raw or aggregated data from the Embrace Plus. +* `read_embrace_plus()` gains additional argument `folder` to choose the folder where the data is stored. This prevents the user to have to navigate to compress the files before using this function. It is still possible to use a zip file as input with the `zipfile` argument. +* `aggregate_data()` and friends (`aggregate_e4_data()`, `aggregate_embrace_plus_data()`, `aggregate_nowatch()`) now have a `interval` argument. It defaults to `"1 min"`, but can be changed if desired. + # wearables 0.10.0 2024-02-27 diff --git a/R/aggregate_data.R b/R/aggregate_data.R index 04f7ba6..7705e8c 100644 --- a/R/aggregate_data.R +++ b/R/aggregate_data.R @@ -1,59 +1,22 @@ -#' Aggregate data into 1min timestamps -#' @param x An object read by \code{\link{read_e4}} or \code{\link{read_embrace_plus}}. +#' Aggregate data into timesteps +#' @param x An object read by \code{\link{read_e4}}, \code{\link{read_embrace_plus}} or \code{\link{read_nowatch}}. +#' @param interval The interval to aggregate the data. Default is 1 min. #' @export -aggregate_data <- function(x) { +aggregate_data <- function(x, interval = "1 min") { - if ("EDA" %in% names(x)) { + for (name in names(x)) { - x$EDA <- padr::thicken(x$EDA, - interval = "1 min", - colname = "datetime_1min" - ) %>% - dplyr::group_by(datetime_1min) %>% - summarize(EDA = mean(EDA)) %>% - dplyr::rename(DateTime = datetime_1min) - - } - - if ("ACC" %in% names(x)) { + if (nrow(x[[name]]) == 0 || !any(c("DateTime", "datetime_1min") %in% colnames(x[[name]]))) { + next + } - x$ACC <- padr::thicken(x$ACC, - interval = "1 min", - colname = "datetime_1min" + x[[name]] <- padr::thicken(x[[name]], + interval = interval, + colname = "datetime_1min" ) %>% - group_by(datetime_1min) %>% - summarize( - x = mean(x), - y = mean(y), - z = mean(z), - a = mean(a) - ) %>% - dplyr::rename(DateTime = datetime_1min) - - } - - if ("TEMP" %in% names(x)) { - - x$TEMP <- padr::thicken(x$TEMP, - interval = "1 min", - colname = "datetime_1min" - ) %>% - group_by(datetime_1min) %>% - summarize(TEMP = mean(TEMP)) %>% - dplyr::rename(DateTime = datetime_1min) - - } - - if ("HR" %in% names(x)) { - - x$HR <- padr::thicken(x$HR, - interval = "1 min", - colname = "datetime_1min" - ) %>% - group_by(datetime_1min) %>% - summarize(HR = mean(HR)) %>% + dplyr::group_by(datetime_1min) %>% + dplyr::summarise(across(where(is.numeric), mean)) %>% dplyr::rename(DateTime = datetime_1min) - } x$BVP <- NULL @@ -66,31 +29,45 @@ aggregate_data <- function(x) { } -#' Aggregate E4 data into 1min timesteps +#' Aggregate E4 data into timesteps #' @rdname aggregate_data #' @export -aggregate_e4_data <- function(x) { +aggregate_e4_data <- function(x, interval = "1 min") { if (is.null(x$EDA)) { warning("Data not found. Did you run rbind_e4()?") } - x <- aggregate_data(x) + x <- aggregate_data(x, interval = interval) return(x) } -#' Aggregate Embrace Plus data into 1min timesteps +#' Aggregate Embrace Plus data into timesteps #' @rdname aggregate_data #' @export -aggregate_embrace_plus_data <- function(x) { +aggregate_embrace_plus_data <- function(x, interval = "1 min") { if (is.null(x$EDA)) { warning("Data not found. Did you run rbind_embrace_plus()?") } - x <- aggregate_data(x) + x <- aggregate_data(x, interval = interval) + + return(x) +} + +#' Aggregate Nowatch data into timesteps +#' @rdname aggregate_data +#' @export +aggregate_nowatch_data <- function(x, interval = "1 min") { + + if (is.null(x$ACT)) { + warning("Data not found. Did you use read_nowatch()?") + } + + x <- aggregate_data(x, interval = interval) return(x) } diff --git a/R/read_and_process_embrace_plus.R b/R/read_and_process_embrace_plus.R index 5bd5e10..554aeb4 100644 --- a/R/read_and_process_embrace_plus.R +++ b/R/read_and_process_embrace_plus.R @@ -2,18 +2,36 @@ #' @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) } else { - flog.info("Raw data read and converted.") + flog.info(sprintf("%s data read and converted.", type)) process_embrace_plus(data) } } @@ -23,7 +41,11 @@ read_and_process_embrace_plus <- function(zipfile, tz = Sys.timezone()) { #' @param data object from read_e4 function process_embrace_plus <- function(data) { - eda_filt <- process_eda(data$EDA) + # omitting NAs: TBD + # the Embrace Plus aggregated files have a lot of NAs, + # for example when the device wasn't able to record anything + # we need to decide how to handle these NAs + eda_filt <- process_eda(na.omit(data$EDA)) flog.info("EDA data filtered.") eda_peaks <- find_peaks(eda_filt) @@ -53,13 +75,34 @@ process_embrace_plus <- function(data) { TEMP_sd = sd(data$TEMP$TEMP) ) - acc_summary <- list( - ACC_mean = mean(data$ACC$a), - ACC_median = median(data$ACC$a), - ACC_min = min(data$ACC$a), - ACC_max = max(data$ACC$a), - ACC_sd = sd(data$ACC$a) - ) + # Determine if ACC is in the data, if not, look for MOVE, if not, set to NA + if ("ACC" %in% names(data)) { + acc_data <- "ACC" + acc_col <- "a" + } else if ("MOVE" %in% names(data)) { + acc_data <- "MOVE" + acc_col <- "accelerometers_std_g" + } else { + acc_data <- "" + } + + if(acc_data != "") { + acc_summary <- list( + ACC_mean = mean(data[[acc_data]][[acc_col]]), + ACC_median = median(data[[acc_data]][[acc_col]]), + ACC_min = min(data[[acc_data]][[acc_col]]), + ACC_max = max(data[[acc_data]][[acc_col]]), + ACC_sd = sd(data[[acc_data]][[acc_col]]) + ) + } else { + acc_summary <- list( + ACC_mean = NA, + ACC_median = NA, + ACC_min = NA, + ACC_max = NA, + ACC_sd = NA + ) + } eda_clean <- dplyr::filter(eda_filt, .data$quality_flag == 1) diff --git a/R/read_embrace_plus.R b/R/read_embrace_plus.R index 1194215..e1f0b5e 100644 --- a/R/read_embrace_plus.R +++ b/R/read_embrace_plus.R @@ -28,6 +28,9 @@ get_timestamp_column <- function(start_time, sampling_freq, len_list, tz) { return(timestamp_df) } + + + #' Create dataframe for psychological factors #' @description Creates a dataframe for psychological factors #' @param data list of dataframes @@ -83,33 +86,153 @@ create_dataframes <- function(data, type, file, vars = c("x", "y", "z"), return(df) } + + + #' Read Embrace Plus data #' @description Reads in Embrace Plus data as a list (with EDA, HR, Temp, ACC, BVP, IBI as dataframes), and prepends timecolumns -#' @details This function reads in a zipfile as exported by Embrace Plus. Then it extracts the zipfiles in a temporary folder -#' and unzips them in the same temporary folder. +#' @details This function reads in a zipfile with data from the Embrace Plus device, or +#' a folder with unzipped files. The unzipped files are avro or csv files. #' -#' The unzipped files are avro files, and are read in with using `sparklyr`, which sets up a local Spark cluster. +#' The unzipped files are avro or csv files, where avro files are read in with using `sparklyr`, which sets up a local Spark cluster. #' #' The function returns an object of class "embrace_plus_data" with a prepended datetime columns. #' The object contains a list with dataframes from the physiological signals. #' -#' @param zipfile A zip file as exported by the instrument +#' @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 or folder. Either "raw" or "aggregated". #' @param tz The timezone used by the instrument (defaults to user timezone). #' @examples -#' library(wearables) -#' # read_embrace_plus("yourpathtohezipfile.zip") +#' \dontrun{ +#' library(wearables) +#' read_embrace_plus(zipfile = "yourpathtohezipfile.zip") +#' read_embrace_plus(folder = "/path/to/folder/with/files", type = "aggregated") +#' } #' @export -#' @import sparklyr #' @import cli #' @importFrom dplyr pull -read_embrace_plus <- function(zipfile, +read_embrace_plus <- function(zipfile = NULL, + folder = NULL, + type = "raw", tz = Sys.timezone()) { - # Check if file exists - if (!file.exists(zipfile)) { + # Check if zipfile or folder is provided + if (is.null(zipfile) && is.null(folder)) { + cli_abort("Either zipfile or folder must be provided") + } + + # Check if file or folder exist + if (!is.null(zipfile) && !file.exists(zipfile)) { cli_abort("File does not exist") } + if (!is.null(folder) && !dir.exists(folder)) { + cli_abort("Folder does not exist") + } + + # Check type + if (!type %in% c("raw", "aggregated")) { + cli_abort("type must be either 'raw' or 'aggregated'") + } + + if (type == "raw") { + return(read_raw_embrace_plus(zipfile, folder, tz)) + } + + if (type == "aggregated") { + return(read_aggregated_embrace_plus(zipfile, folder, tz)) + } + +} + + + + +#' Extract csv files from data +#' @description Processes .csv files +#' @param zipfile path to zipfile +#' @param folder path to folder +#' @param tz timezone +#' @keywords internal +#' @import cli +#' @noRd +read_aggregated_embrace_plus <- function(zipfile = NULL, folder = NULL, tz) { + + if (!is.null(zipfile)) { + csv_files <- unzip_files(zipfile, "csv") + } + + if (!is.null(folder)) { + # check if there is a subdirectory first + if (length(list.files(folder, full.names = TRUE)) == 1) { + folder <- list.files(folder, full.names = TRUE) + } + + csv_files <- list.files(folder, pattern = ".csv", full.names = TRUE) + } + + # Get the content before .csv and after the last _ (but include -) + dataset_names <- gsub(".*?([A-Za-z0-9\\-]+)[.]csv", "\\1", csv_files) + dataset_names <- toupper(dataset_names) + dataset_names <- gsub("TEMPERATURE", "TEMP", dataset_names) + dataset_names <- gsub("SLEEP-DETECTION", "SLEEP", dataset_names) + dataset_names <- gsub("PULSE-RATE", "HR", dataset_names) + dataset_names <- gsub("MOVEMENT-INTENSITY", "MOVE", dataset_names) + dataset_names <- gsub("RESPIRATORY-RATE", "RR", dataset_names) + dataset_names <- gsub("WEARING-DETECTION", "WEAR", dataset_names) + csv_files <- setNames(csv_files, dataset_names) + + csv_list <- list() + + for (i in 1:length(csv_files)) { + + file <- csv_files[i] + + this_file <- read.csv(file, stringsAsFactors = FALSE) + + rename_cols <- list(c("timestamp_iso", "DateTime"), + c("timestamp_unix", "unix_timestamp"), + c("eda_scl_usiemens", "EDA"), + c("temperature_celsius", "TEMP"), + c("pulse_rate_bpm", "HR")) + + for (j in rename_cols) { + if (j[[1]] %in% colnames(this_file)) { + names(this_file)[names(this_file) == j[[1]]] <- j[[2]] + } + } + + # further pre-processing + this_file$DateTime <- as.POSIXct(gsub("T|Z", " ", this_file$DateTime), tz = tz) + + csv_list[[names(file)]] <- this_file + + } + + return( + structure(csv_list, + class = "embraceplusdata", + zipfile = tools::file_path_sans_ext(zipfile), + tz = tz + ) + ) + +} + + + +#' Extracts avro files from raw data +#' @description Processes .avro files +#' @param zipfile zip file +#' @param folder folder +#' @param tz timezone +#' @keywords internal +#' @import sparklyr +#' @import cli +#' @noRd +read_raw_embrace_plus <- function(zipfile = NULL, folder = NULL , tz) { + # Check for already installed Spark versions # if none available, install the latest version if (nrow(spark_available_versions()) == 0) { @@ -125,18 +248,13 @@ read_embrace_plus <- function(zipfile, packages = "org.apache.spark:spark-avro_2.12:3.5.0") cli_alert_success("Connected!") - # Extract files to a temporary folder - path <- paste0(tempdir(), "/extracted") - - # if path exists, remove content - if (dir.exists(path)) { - unlink(path, recursive = TRUE) + if (!is.null(zipfile)) { + avro_files <- unzip_files(zipfile, type = "avro") } - unzip(zipfile = zipfile, - exdir = path) - - avro_files <- list.files(path, recursive = TRUE, pattern = "[.]avro$", full.names = TRUE) + if (!is.null(folder)) { + avro_files <- list.files(folder, pattern = ".avro", full.names = TRUE) + } cli_alert_info("About to start processing {length(avro_files)} avro file{?s}") @@ -244,11 +362,6 @@ read_embrace_plus <- function(zipfile, # Disconnect from the Spark cluster spark_disconnect(sc) - return( - structure(avro_list, - class = "embraceplusdata", - zipfile = tools::file_path_sans_ext(zipfile), - tz = tz - ) - ) + return(avro_list) + } diff --git a/R/read_nowatch.R b/R/read_nowatch.R new file mode 100644 index 0000000..05e84c6 --- /dev/null +++ b/R/read_nowatch.R @@ -0,0 +1,96 @@ +#' Read Nowatch data +#' @description Reads in Nowatch data as a list, and prepends timecolumns +#' @details This function reads in a zipfile with files exported by the Nowatch instrument, +#' or a folder with the unzipped files. The files are expected to be csv files. +#' +#' The unzipped files are csv files. +#' +#' The function returns an object of class "nowatch_data" with a prepended datetime columns. +#' The object contains a list with dataframes from the physiological signals. +#' +#' @param zipfile A zip file as exported by the instrument. Only aggregated data supported. +#' @param folder A folder with the unzipped files. If this is provided, the zipfile is not used. +#' @param tz The timezone used by the instrument (defaults to user timezone). +#' @examples +#' \dontrun{ +#' library(wearables) +#' read_nowatch("yourpathtohezipfile.zip") +#' read_nowatch(folder = "/path/to/folder/with/files") +#' } +#' @export +#' @import cli +read_nowatch <- function(zipfile = NULL, + folder = NULL, + tz = Sys.timezone()) { + + # Check if zipfile or folder is provided + if (is.null(zipfile) && is.null(folder)) { + cli_abort("Please provide a zipfile or a folder") + } + + # Check if zipfile exists + if (!is.null(zipfile) && !file.exists(zipfile)) { + cli_abort("File does not exist") + } + + # Check if folder exists + if (!is.null(folder) && !dir.exists(folder)) { + cli_abort("Folder does not exist") + } + + # Unzip the files + if (!is.null(zipfile)) { + csv_files <- unzip_files(zipfile, "csv") + } + + if (!is.null(folder)) { + csv_files <- list.files(folder, full.names = TRUE) + } + + # Get the content before .csv and after the last _ (but include -) + dataset_names <- gsub(".*?([A-Za-z0-9\\-]+)[.]csv", "\\1", csv_files) + dataset_names <- toupper(dataset_names) + dataset_names <- gsub("ACTIVITYTYPE", "ACT", dataset_names) + dataset_names <- gsub("CADENCE", "CAD", dataset_names) + dataset_names <- gsub("TEMPERATURE", "TEMP", dataset_names) + dataset_names <- gsub("CORTISOLLEVELS", "CORTL", dataset_names) + dataset_names <- gsub("HEARTBEATS", "HBR", dataset_names) + dataset_names <- gsub("HEARTRATE", "HR", dataset_names) + dataset_names <- gsub("RESPIRATIONRATE", "RR", dataset_names) + dataset_names <- gsub("SLEEPSESSION", "SLEEP", dataset_names) + dataset_names <- gsub("STRESSLEVEL", "STRESS", dataset_names) + csv_files <- setNames(csv_files, dataset_names) + + csv_list <- list() + + for (i in 1:length(csv_files)) { + + file <- csv_files[i] + + this_file <- read.csv(file, stringsAsFactors = FALSE) + + rename_cols <- list(c("timestamp", "unix_timestamp"), + c("value", names(file))) + + for (j in rename_cols) { + if (j[[1]] %in% colnames(this_file)) { + names(this_file)[names(this_file) == j[[1]]] <- j[[2]] + } + } + + # convert unix timestamp to as.POSIXct + if ("unix_timestamp" %in% colnames(this_file)) { + this_file$DateTime <- as.POSIXct(this_file$unix_timestamp, origin = "1970-01-01", tz = tz) + } + + csv_list[[names(file)]] <- this_file + + } + + return( + structure(csv_list, + class = "nowatchdata", + zipfile = tools::file_path_sans_ext(zipfile), + tz = tz + )) +} \ No newline at end of file diff --git a/R/utils.R b/R/utils.R index 170a476..d92dfc8 100644 --- a/R/utils.R +++ b/R/utils.R @@ -112,3 +112,28 @@ create_empty_freq_list <- function() { return(freq_empty_list) } + + +#' Unzip files and store files in temporary directory +#' @description Extracts avro or csv files from a zip file +#' @param zipfile path to the zip file +#' @param type type of file to extract +#' @keywords internal +#' @noRd +unzip_files <- function(zipfile, type) { + + # Extract files to a temporary folder + path <- paste0(tempdir(), "/extracted") + + # if path exists, remove content + if (dir.exists(path)) { + unlink(path, recursive = TRUE) + } + + unzip(zipfile = zipfile, + exdir = path) + + files <- list.files(path, recursive = TRUE, pattern = sprintf("[.]%s$", type), full.names = TRUE) + + return(files) +} diff --git a/man/aggregate_data.Rd b/man/aggregate_data.Rd index 337d918..825b814 100644 --- a/man/aggregate_data.Rd +++ b/man/aggregate_data.Rd @@ -4,21 +4,28 @@ \alias{aggregate_data} \alias{aggregate_e4_data} \alias{aggregate_embrace_plus_data} -\title{Aggregate data into 1min timestamps} +\alias{aggregate_nowatch_data} +\title{Aggregate data into timesteps} \usage{ -aggregate_data(x) +aggregate_data(x, interval = "1 min") -aggregate_e4_data(x) +aggregate_e4_data(x, interval = "1 min") -aggregate_embrace_plus_data(x) +aggregate_embrace_plus_data(x, interval = "1 min") + +aggregate_nowatch_data(x, interval = "1 min") } \arguments{ -\item{x}{An object read by \code{\link{read_e4}} or \code{\link{read_embrace_plus}}.} +\item{x}{An object read by \code{\link{read_e4}}, \code{\link{read_embrace_plus}} or \code{\link{read_nowatch}}.} + +\item{interval}{The interval to aggregate the data. Default is 1 min.} } \description{ -Aggregate data into 1min timestamps +Aggregate data into timesteps + +Aggregate E4 data into timesteps -Aggregate E4 data into 1min timesteps +Aggregate Embrace Plus data into timesteps -Aggregate Embrace Plus data into 1min timesteps +Aggregate Nowatch data into timesteps } diff --git a/man/read_and_process_embrace_plus.Rd b/man/read_and_process_embrace_plus.Rd index 2fdd367..52b6159 100644 --- a/man/read_and_process_embrace_plus.Rd +++ b/man/read_and_process_embrace_plus.Rd @@ -4,11 +4,20 @@ \alias{read_and_process_embrace_plus} \title{Read, process and feature extraction of Embrace Plus data} \usage{ -read_and_process_embrace_plus(zipfile, tz = Sys.timezone()) +read_and_process_embrace_plus( + zipfile = NULL, + folder = NULL, + type = "raw", + tz = Sys.timezone() +) } \arguments{ \item{zipfile}{zip file with embrace plus data to be read} +\item{folder}{A folder with the unzipped files. If this is provided, the zipfile is not used.} + +\item{type}{The type of data contained in the zip file. Either "raw" or "aggregated".} + \item{tz}{timezone where data were recorded (default system timezone)} } \value{ diff --git a/man/read_embrace_plus.Rd b/man/read_embrace_plus.Rd index 0ef0c84..66ef607 100644 --- a/man/read_embrace_plus.Rd +++ b/man/read_embrace_plus.Rd @@ -4,10 +4,19 @@ \alias{read_embrace_plus} \title{Read Embrace Plus data} \usage{ -read_embrace_plus(zipfile, tz = Sys.timezone()) +read_embrace_plus( + zipfile = NULL, + folder = NULL, + type = "raw", + tz = Sys.timezone() +) } \arguments{ -\item{zipfile}{A zip file as exported by the instrument} +\item{zipfile}{A zip file as exported by the instrument. Can be aggregated data, or raw data.} + +\item{folder}{A folder with the unzipped files. If this is provided, the zipfile is not used.} + +\item{type}{The type of data contained in the zip file or folder. Either "raw" or "aggregated".} \item{tz}{The timezone used by the instrument (defaults to user timezone).} } @@ -15,15 +24,18 @@ read_embrace_plus(zipfile, tz = Sys.timezone()) Reads in Embrace Plus data as a list (with EDA, HR, Temp, ACC, BVP, IBI as dataframes), and prepends timecolumns } \details{ -This function reads in a zipfile as exported by Embrace Plus. Then it extracts the zipfiles in a temporary folder -and unzips them in the same temporary folder. +This function reads in a zipfile with data from the Embrace Plus device, or +a folder with unzipped files. The unzipped files are avro or csv files. -The unzipped files are avro files, and are read in with using `sparklyr`, which sets up a local Spark cluster. +The unzipped files are avro or csv files, where avro files are read in with using `sparklyr`, which sets up a local Spark cluster. The function returns an object of class "embrace_plus_data" with a prepended datetime columns. The object contains a list with dataframes from the physiological signals. } \examples{ -library(wearables) -# read_embrace_plus("yourpathtohezipfile.zip") +\dontrun{ + library(wearables) + read_embrace_plus(zipfile = "yourpathtohezipfile.zip") + read_embrace_plus(folder = "/path/to/folder/with/files", type = "aggregated") +} } diff --git a/man/read_nowatch.Rd b/man/read_nowatch.Rd new file mode 100644 index 0000000..92e553d --- /dev/null +++ b/man/read_nowatch.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/read_nowatch.R +\name{read_nowatch} +\alias{read_nowatch} +\title{Read Nowatch data} +\usage{ +read_nowatch(zipfile = NULL, folder = NULL, tz = Sys.timezone()) +} +\arguments{ +\item{zipfile}{A zip file as exported by the instrument. Only aggregated data supported.} + +\item{folder}{A folder with the unzipped files. If this is provided, the zipfile is not used.} + +\item{tz}{The timezone used by the instrument (defaults to user timezone).} +} +\description{ +Reads in Nowatch data as a list, and prepends timecolumns +} +\details{ +This function reads in a zipfile with files exported by the Nowatch instrument, +or a folder with the unzipped files. The files are expected to be csv files. + +The unzipped files are csv files. + +The function returns an object of class "nowatch_data" with a prepended datetime columns. +The object contains a list with dataframes from the physiological signals. +} +\examples{ +\dontrun{ + library(wearables) + read_nowatch("yourpathtohezipfile.zip") + read_nowatch(folder = "/path/to/folder/with/files") +} +}