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

R and RStudio Installation

If you do not already have an environment ready to run R code, we recommend installing it along with RStudio. For more information on this process, please see here.

Project Setup

Once you have RStudio up and running, we suggest creating a new R project and placing all ECG XML files in a sub-directory. The file structure may look something like this:

Folder Structure

The RStudio file panel may look something like this:

Folder Structure

Installing easyRecg

You can run the following lines of code to install easyRecg. Depending on what dependencies you already have in your compute environment, this could take several minutes:

install.packages("devtools")
devtools::install_github("rickeycarter/easyRecg")

Extracting Data

Once you have your environment configured, you can start using the package to extract your data. We recommend including all the code below in a single R script that can be saved and shared.

Load the easyRecg package:

devtools::load_all(".")
library(easyRecg)
dir.create('ecg_files')
from <- system.file("extdata", path = "muse", package = "easyRecg")
to <- "ecg_files"
files <- list.files(from, full.names = TRUE)
file.copy(files, to, recursive = TRUE)

Extract and save the ECG 12-lead data

all_muse <- read_muse_xml_directory("ecg_files")
save(all_muse, file = "ecg_lead_data.Rda")

Extract and save meta data

For more info on whitelisting, blacklisting, or mixed filtering, please see the readme.

# Get list of files to read
all_files <- list.files("ecg_files", full.names = TRUE)

# Decide what meta data to share - this can be changes
exclude <- list(
  patient_demographics = c("patient_last_name", "patient_first_name")
)

meta_data <- read_muse_xml_meta(all_files, exclude = exclude)

# Inspect data - ensure it only contains appropriate data
meta_data

# save data
save(meta_data, file = "ecg_meta_data.Rda")
file.remove("ecg_meta_data.Rda")
file.remove("ecg_lead_data.Rda")
unlink("ecg_files", recursive=TRUE)


rickeycarter/easyRecg documentation built on Dec. 22, 2021, 4:09 p.m.