Skip to content

Commit

Permalink
internal recoding of topoplot to play nice with tidy; initial dplyr s…
Browse files Browse the repository at this point in the history
…tyle functions
  • Loading branch information
craddm committed Nov 22, 2018
1 parent ff52c08 commit 3c7e381
Show file tree
Hide file tree
Showing 10 changed files with 257 additions and 135 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ importFrom(purrr,is_empty)
importFrom(purrr,map)
importFrom(purrr,map_df)
importFrom(purrr,partial)
importFrom(rlang,current_env)
importFrom(rlang,parse_quo)
importFrom(rlang,parse_quosure)
importFrom(scales,squish)
importFrom(signal,butter)
importFrom(signal,decimate)
Expand Down
5 changes: 4 additions & 1 deletion R/data_averaging.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ eeg_average.eeg_epochs <- function(data,
} else {

# Check for presence of labels
lab_check <- label_check(cond_label, unique(list_epochs(data)$event_label))
lab_check <- label_check(cond_label,
unique(list_epochs(data)$event_label))

if (!all(lab_check)) {
stop("Not all labels found. Use list_events to check labels.")
}

evoked <- vector("list", length(cond_label))

for (i in seq_along(cond_label)) {
tmp_dat <- select_epochs(data,
epoch_events = cond_label[[i]])
Expand All @@ -71,6 +73,7 @@ eeg_average.eeg_epochs <- function(data,
row.names(evoked[[i]]) <- NULL
}
data$signals <- evoked

if (length(cond_label) > 1) {
names(data$signals) <- cond_label
} else {
Expand Down
37 changes: 37 additions & 0 deletions R/dplyr-extenstions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#' @noRd
filter.eeg_epochs <- function(.data, ...) {
.data$signals <- as.data.frame(.data)
.data$signals <- dplyr::filter(.data$signals, ...)
.data$signals$time <- NULL
.data$signals$epoch <- NULL
.data$timings <- dplyr::filter(.data$timings, ...)
.data
}

#' @noRd
filter.eeg_data <- function(.data, ...) {
.data$signals <- as.data.frame(.data)
.data$signals <- dplyr::filter(.data$signals, ...)
.data$signals$time <- NULL
.data$signals$sample <- NULL
.data$timings <- dplyr::filter(.data$timings, ...)
.data
}

#' @noRd
select.eeg_epochs <- function(.data, ...) {
.data$signals <- dplyr::select(.data$signals, ...)
if (!is.null(.data$chan_info)) {
.data$chan_info <- .data$chan_info[.data$chan_info$electrode %in% names(.data$signals), ]
}
.data
}

#' @noRd
select.eeg_data <- function(.data, ...) {
.data$signals <- dplyr::select(.data$signals, ...)
if (!is.null(.data$chan_info)) {
.data$chan_info <- .data$chan_info[.data$chan_info$electrode %in% names(.data$signals), ]
}
.data
}
3 changes: 2 additions & 1 deletion R/epoch_images.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ erp_image.eeg_epochs <- function(data,
clim = NULL,
interpolate = FALSE,
...) {
if (!electrode %in% names(data$signals)) {

if (!electrode %in% names(data$signals)) {
stop("Specified electrode not found.")
}
data <- select_elecs(data,
Expand Down
Loading

0 comments on commit 3c7e381

Please sign in to comment.