knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

I address some potential sources of confusion here. To run this examples, we first load eeguana and dplyr:

library(eeguana)
library(dplyr)

Tidyverse dplyr-like functions

The package {eeguana} allows for functions that look like {dplyr} functions but they truly are powered by {tidy.table} and {data.table}. This means that there are subtle differences between dplyr's behavior and eeguana dplyr-like function behavior.

Default values

The default values of the arguments might be different, and some arguments might not exist for the eeguana dplyr-like functions.

Referring back to recently created channels

Unlike dplyr's mutate, {eeguana}'s [mutate] doesn't allow to refer back to a recently created channel:

new_data <- data_faces_ERPs %>%
  eeg_mutate(X = scale(C3), Y = X * 2)

A workaround is to use two mutates:

new_data <- data_faces_ERPs %>%
  eeg_mutate(X = scale(C3)) %>%
  eeg_mutate(Y = X * 2)

Dplyr-like functions not only edit the eeg_lst objects but they also do book-keeping: They remove unnecessary channels, or update their information and they ensure that three tables (signal, segments, and events) match. It's then not recommended to edit the signal and segments table directly.

Compare the correct way to filter out samples:

new_data <- data_faces_10_trials %>%
  eeg_filter(.sample < 20000)
events_tbl(new_data)

with the non-recommended version:

new_data_BAD <- data_faces_10_trials
new_data_BAD$.signal <- new_data_BAD$.signal %>%
  filter(.sample < 20000)
events_tbl(new_data_BAD)

In some occasions, the events or the channels tables need to be edited. In those cases, one can use events_tbl(data_eeg) <- ... or channels_tbl(data_eeg) <- ...).

channels_tbl(data_faces_10_trials)
new_data <- data_faces_10_trials
channels_tbl(new_data) <- channels_tbl(new_data) %>%
  mutate(resolution = .1)
channels_tbl(new_data)
events_tbl(new_data) %>%
  head()
events_tbl(new_data) <- events_tbl(new_data) %>%
  filter(.description != "s130")
events_tbl(new_data) %>%
  head()

Losing the channel properties

Some functions keep the channel properties, e.g., mean, scale.

head(signal_tbl(data_faces_10_trials)$Oz)
head(mean(signal_tbl(data_faces_10_trials)$Oz))

Some primitive functions remove the channel properties, e.g., min, var.

head(min(signal_tbl(data_faces_10_trials)$Oz))
head(var(signal_tbl(data_faces_10_trials)$Oz))

A possible workaround is the following:

head(min(signal_tbl(data_faces_10_trials)$Oz)) + 0 * signal_tbl(data_faces_10_trials)$Oz[1]


bnicenboim/eeguana documentation built on March 16, 2024, 7:21 a.m.