Title: IEEG (Intracranial Electroencephalography) Epoch Data Tools
Version: 1.0.3
Description: Provides tools for working with iEEG matrix data, including downloading curated iEEG data from OSF (The Open Science Framework https://osf.io/) (EpochDownloader()), making new objects (Epoch()), processing (crop() and resample()), and visualizing the data (plot()).
License: GPL (≥ 3)
Encoding: UTF-8
RoxygenNote: 7.3.2
Biarch: true
Depends: R (≥ 4.1)
Imports: ggplot2, methods, ramify, TableContainer, glue, osfr, jsonlite, rlang, ggtext, gsignal
SystemRequirements: GNU make
Suggests: knitr, rmarkdown, testthat (≥ 3.0.0)
Config/testthat/edition: 3
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2025-08-29 20:55:01 UTC; jiewang
Author: Jiefei Wang [aut, cre]
Maintainer: Jiefei Wang <szwjf08@gmail.com>
Repository: CRAN
Date/Publication: 2025-09-03 21:30:07 UTC

Check and keep valid index only

Description

Check and keep valid index only

Usage

.checkIndex(indices, names)

Arguments

indices

Numeric or character index to check

names

Character. All names corresponding to the indices


Standardize iEEG row data for plotting

Description

Standardize iEEG row data for plotting

Usage

.standardizeIEEG(data)

Arguments

data

Matrix or data frame of iEEG data

Value

Standardized data matrix


Constructor for Epoch class

Description

Constructor for Epoch class

Usage

Epoch(
  table,
  electrodes = NULL,
  times = NULL,
  startTime = NULL,
  samplingRate = NULL,
  rowData = NULL,
  colData = NULL,
  metaData = NULL
)

Arguments

table

Matrix containing epoch data (rows=electrodes, columns=time points)

electrodes

Optional character vector for electrode names, if not provided, row names of data are used. If row names are also not available, there will be no electrode names.

times

Optional numeric vector of time points.

startTime

Optional numeric value for start time, if provided, times will be calculated based on this and samplingRate.

samplingRate

Optional numeric value for sampling rate, if provided, times will be calculated based on this and startTime.

rowData

Optional data frame containing metadata for rows (electrodes).

colData

Optional data frame containing metadata for columns (time points).

metaData

Optional list containing metadata for the Epoch object. Element name "SamplingRate" is reserved by the Epoch class.

Value

An Epoch object

Examples

epoch_data <- matrix(rnorm(1000), nrow = 10)
rownames(epoch_data) <- paste0("Electrode_", 1:10)
epoch <- Epoch(epoch_data, startTime = 0, samplingRate = 100)


Epoch Class

Description

S4 class to handle epoch data with electrodes and time points

Slots

table

a matrix containing iEEG data (columns=time points, rows=electrodes)

colData

a data frame containing metadata for columns (time points)

rowData

a data frame containing metadata for rows (electrodes)

metaData

a list containing metadata for the Epoch object


EpochDownloader constructor

Description

Manually update the project list from the remote repository. This function will attempt to download the latest configuration from the GitHub repository. If it fails, the current configuration will remain unchanged.

This function returns the list of available projects. If the configuration has not been fetched yet, it will automatically update the project list from the remote repository.

Usage

EpochDownloader(id = NULL, progress = TRUE, verbose = FALSE, path = NULL)

## S4 method for signature 'EpochDownloader'
names(x)

## S4 method for signature 'EpochDownloader'
x[i]

## S4 method for signature 'EpochDownloader'
x$name

## S4 method for signature 'EpochDownloader'
x[[i]]

## S4 method for signature 'EpochDownloader'
show(object)

## S4 method for signature 'EpochDownloader'
length(x)

wiki(x, ...)

## S4 method for signature 'EpochDownloader'
wiki(x)

updateRepos(verbose = FALSE)

EpochRepos(verbose = TRUE)

Arguments

id

Either the ID of an OSF project or the name of an iEEG projects (case insensitive). Check the available projects using EpochRepos(). The default points to the fragility data from the Fragility multi-center retrospective study.

progress

Logical indicating whether to show progress during download.

verbose

Logical indicating whether to show messages

path

The path to the temporary folder where the files will be downloaded.

x

An EpochDownloader object.

i

Index or name of the files to be accessed.

name

The name of the file to be accessed.

object

An EpochDownloader object.

...

Not used, for future extensibility

Value

EpochDownloader: An EpochDownloader object.

names: A character vector of file names.

[: A named list of Epoch objects. The names are the dataset names.

$: A single Epoch object.

[[: A single Epoch object.

show: Prints a summary of the EpochDownloader object.

length: Returns the number of files in the EpochDownloader object.

wiki: Opens the wiki page in the default browser

updateRepos: No return value, called for side effects.

EpochRepos: A list of project names and their corresponding OSF project IDs.

Examples

# list all available projects
EpochRepos()

# downloader for the fragility data
dl <- EpochDownloader(id = "fragility")

# list all Epoch objects in the downloader
names(dl)

# download the first Epoch object

 dl[1]
 # equivalent to (index by name)
 dl[names(dl)[1]]


# download the multiple Epoch objects

 dl[c(1, 2)]
 # equivalent to (index by name)
 dl[names(dl)[c(1, 2)]]


EpochRepos()

EpochDownloader

Description

EpochDownloader is a class that allows downloading and accessing files from a OSF project.

Slots

id

The ID of the OSF project.

files

The files in the OSF project.

dataNames

The names of the files in the OSF project.

tmp_folder

The temporary folder where the files are downloaded.

progress

Logical indicating whether to show progress during download.


Obtain the time points for the Epoch matrix

Description

Obtain the time points for the Epoch matrix

Usage

coltimes(x)

## S4 method for signature 'Epoch'
coltimes(x)

Arguments

x

An Epoch object

Value

A numeric vector of time points, or column indices if time points are not defined

See Also

Other Epoch methods: crop(), plot,Epoch,missing-method, resample(), show,Epoch-method

Examples

# Create an Epoch object
epoch_data <- matrix(rnorm(1000), nrow = 10)
rownames(epoch_data) <- paste0("Electrode_", 1:10)
epoch <- Epoch(epoch_data, startTime = 0, samplingRate = 100)

# get the time points of an Epoch object
coltimes(epoch)


Methods for Epoch class

Description

Truncating iEEG data to a specific time range.

Usage

crop(x, start, end, ...)

## S4 method for signature 'Epoch'
crop(x, start, end, checkTimeRange = TRUE)

Arguments

x

An Epoch object

start

Numeric value specifying start of new time range

end

Numeric value specifying end of new time range

...

Not used

checkTimeRange

Logical, whether to check the validity of the time range. This includes checking if the time range is empty, if start is greater than end, and if start or end are out of bounds. Default is TRUE.

Value

clip the time range of the Epoch object

See Also

Other Epoch methods: coltimes(), plot,Epoch,missing-method, resample(), show,Epoch-method

Examples

# Create an Epoch object
epoch_data <- matrix(rnorm(1000), nrow = 10)
rownames(epoch_data) <- paste0("Electrode_", 1:10)
epoch <- Epoch(epoch_data, startTime = 0, samplingRate = 100)

# crop the epoch
crop(epoch, start = 0.5, end = 1.5)


Wrapper functions for calling TableContainer methods

Description

Wrapper functions for calling TableContainer methods

Usage

## S4 method for signature 'Epoch'
dim(x)

## S4 method for signature 'Epoch'
dimnames(x)

## S4 method for signature 'Epoch'
x[i, j, ..., drop = TRUE]

Arguments

x

An Epoch object

i

Row indices for subsetting. If only i is provided, it will return the entire row(s).

j

Column indices for subsetting.

...

Additional arguments.

drop

Not used.

Value

[: A new Epoch object with the selected data.

Examples


# Create an Epoch object
epoch_data <- matrix(rnorm(1000), nrow = 10)
rownames(epoch_data) <- paste0("Electrode_", 1:10)
epoch <- Epoch(epoch_data, startTime = 0, samplingRate = 100)

# wrappers
dim(epoch)
dimnames(epoch)
epoch[1]


Get configuration data from remote URL

Description

Get configuration data from remote URL

Usage

get_config_data()

Value

A list of project configurations


Plot method for Epoch objects

Description

Plot method for Epoch objects

Usage

## S4 method for signature 'Epoch,missing'
plot(
  x,
  y,
  gap = 2,
  groupIndex = NULL,
  timeResolution = 2048,
  maxLabels = 50,
  x.lab.size = 2,
  ...
)

Arguments

x

An Epoch object

y

Not used (for S4 method compatibility)

gap

Numeric value specifying the gap between electrode traces (default: 2)

groupIndex

Integer or string. A group of electrodes to show together in a different color. If NULL(default), all electrodes are shown in the same color.

timeResolution

Maximum number of time points to keep for each electrode (default: 2048)

maxLabels

Maximum number of electrode labels to display on the y-axis (default: 50)

x.lab.size

Size of the x-axis label text (default: 2)

...

Additional arguments (not currently used)

Value

plot: A ggplot object showing iEEG electrode traces

See Also

Other Epoch methods: coltimes(), crop(), resample(), show,Epoch-method

Examples

# Create an Epoch object
epoch_data <- matrix(rnorm(1000), nrow = 10)
rownames(epoch_data) <- paste0("Electrode_", 1:10)
epoch <- Epoch(epoch_data, startTime = 0, samplingRate = 100)

# Plot the epoch
plot(epoch)



Generic function for resampling objects

Description

This function allows you to resample an object to a different sampling frequency.

This function allows you to resample an Epoch object to a different sampling frequency.

Usage

resample(x, ...)

## S4 method for signature 'Epoch'
resample(x, samplingRate, ...)

Arguments

x

An Epoch object to be resampled.

...

Additional arguments passed to gsignal::resample

samplingRate

The new sampling frequency (unit: Hertz).

Value

An Epoch object with the resampled data.

See Also

Other Epoch methods: coltimes(), crop(), plot,Epoch,missing-method, show,Epoch-method

Examples

# Create an Epoch object
epoch_data <- matrix(rnorm(1000), nrow = 10)
rownames(epoch_data) <- paste0("Electrode_", 1:10)
epoch <- Epoch(epoch_data, startTime = 0, samplingRate = 100)

# downsample the epoch to 50 Hz
resample(epoch, samplingRate = 50)

# upsample the epoch to 200 Hz
resample(epoch, samplingRate = 200)


Print the Epoch Object

Description

Print the Epoch Object

Usage

## S4 method for signature 'Epoch'
show(object)

Arguments

object

Epoch object

Value

returns an invisible NULL

See Also

Other Epoch methods: coltimes(), crop(), plot,Epoch,missing-method, resample()