agd: R6 class: 'agd'

agdR Documentation

R6 class: agd

Description

agd is an R6 class that runs a data processing pipeline on one or more jobs that include two .agd (ActiGraph; github.com/actigraph) accelerometer files with LowFrequencyExtension and Normal filters per participant. This class makes calls to the agd_worker R6 class.

Public fields

args

A list of arguments passed into agd$new(). See documentation for agd$new() for details.

log

A tibble with method, timestamp, status, and message vectors providing a record of events during the pipeline run.

jobs

A tibble with vectors based on the args passed into agd$new() representing jobs to be run that are distributed across the number of CPUs set by cpu_max in agd$new().

results

A list of five tibbles (summary_full, summary_full_stc, summary_run, summary_sleeping_hours, summary_waking_hours) summarizing pipeline run(s).

Methods

Public methods


agd$new()

This method creates an instance of an agd_worker class.

Usage
agd$new(
  id,
  age,
  agd_lfe,
  agd_nml,
  epoch_length = 60,
  day_max = 7,
  sleep_algo = "barreira",
  non_wear_algo = "barreira",
  start_date = NA,
  cpu_max = 1,
  dir = NA
)
Arguments
id

Required: a vector representing unique participant ID(s).

age

Required: an integer vector representing participant age(s) in years.

agd_lfe

Required: a character vector representing the full path to .agd file(s) with the LowFrequencyExtension filter.

agd_nml

Required: a character vector representing the full path to .agd file(s) with the Normal filter.

epoch_length

Required (default: 60): an integer vector (length-one or the same length as id) representing the epoch length(s) at which to process the data. Statistics Canada currently uses 15 for participants under 18 years and 60 for participants at all other ages. Note: if sleep_algo is set to "barreira" and epoch_length is set to 15, the sleep algorithm will be applied to 60-second epoch data and the results will be applied to the 15-second epoch data.

day_max

Required (default: 7): an integer vector (length-one or the same length as id) representing the maximum number of days of data to load from agd_lfe and agd_nml.

sleep_algo

Required (default: "barreira"): a character vector (length-one or the same length as id) representing the sleep algorithm to apply. Options currently include "barreira". See apply_barreira_algo() for more details.

non_wear_algo

Required (default: "barreira"): a character vector (length-one or the same length as id) representing the non-wear algorithm to apply. Options currently include "barreira", "20-min-algo", "60-min-algo", "90-min-algo" and "choi". See apply_barreira_algo() and apply_non_wear_algo() for more details.

start_date

Optional (default: NA): a character or date vector (format: yyyy-mm-dd) that is length-one or the same length as id representing the first day of data to load from agd_lfe and agd_nml. If not set, data will be loaded from the first available day until day_max is reached.

cpu_max

Required (default: 1): a length-one integer vector representing the number of CPUs to distribute the data processing across.

dir

Optional (default: NA): a length-one character vector representing the full path to the location where the results list will be exported tibble by tibble in .csv format.

Returns

Returns an object of class agd.


agd$run()

This method iterates jobs and calls run_agd_job().

Usage
agd$run()
Returns

Returns the results list from an agd_worker object and binds it to self (an instance of agd).


agd$export()

This method exports self$results tibble by tibble in .csv format.

Usage
agd$export(dir = self$args$dir, stc = FALSE)
Arguments
dir

Optional (default: self$args$dir): a length-one character vector representing the full path to the location where the results list will be exported tibble by tibble in .csv format.

stc

Optional (default: FALSE): a length-one logical vector indicating whether to export only statcan-formatted results.

Returns

Returns the agd object (self) invisibly.


agd$print()

This method renders details (arguments, issues, log) about an instance agd to the console.

Usage
agd$print()
Returns

Returns the agd object (self) invisibly.


agd$sanity_check()

This method renders a sanity check report in .html format.

Usage
agd$sanity_check(
  name = "sanity-check-report",
  id = self$jobs$id,
  dir = self$args$dir,
  include_plot = FALSE
)
Arguments
name

Required (default: "sanity-check-report"): a length-one character vector representing the file name of the report.

id

Required (default: self$jobs$id): a vector representing unique participant ID(s).

dir

Required (default: self$args$dir): a length-one character vector representing the full path to the location where the report will be exported in .html format.

include_plot

Optional (default: FALSE): a length-one logical vector representing whether to render scatterplots.

Returns

Returns an .html-formatted report.


agd$view()

This method renders data frames from ⁠$results⁠ in tab.

Usage
agd$view(results = c(names(self$results), "issues", "log"))
Arguments
results

Optional (default: c(names(self$results), "issues", "log")): a character vector representing the results to render to tab. Options include: "summary_full", "summary_full_stc", "summary_run", "summary_sleeping_hours", "summary_waking_hours", "issues", "log".

Returns

Returns the agd object (self) invisibly.


agd$clone()

The objects of this class are cloneable with this method.

Usage
agd$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

# Create meta data frame (external/non-statcan users)
meta <- data.frame(
  id = c("jane-canuck", "john-canuck"),
  age = c(10, 40),
  agd_lfe = c(
    system.file("extdata", "jane-canuck-lfe.agd", package = "chms"),
    system.file("extdata", "john-canuck-lfe.agd", package = "chms")
  ),
  agd_nml = c(
    system.file("extdata", "jane-canuck-nml.agd", package = "chms"),
    system.file("extdata", "john-canuck-nml.agd", package = "chms")
  ),
  start_date = c("2021-05-30", "2021-05-27"),
  epoch_length = c(15, 60)
)

# Initialize agd R6 class
agd_data <- agd$new(
  id = meta$id,
  age = meta$age,
  agd_lfe = meta$agd_lfe,
  agd_nml = meta$agd_nml,
  epoch_length = meta$epoch_length,
  day_max = 2,
  sleep_algo = "barreira",
  non_wear_algo = "barreira",
  start_date = meta$start_date,
  cpu_max = 1
)

# Run data processing pipeline (load, clean, classify and summarize data)
agd_data$run()

chms documentation built on Oct. 17, 2026, 5:07 p.m.

Related to agd in chms...