filter_carbs: Filter carbohydrate entries

View source: R/04_filtering.R

filter_carbsR Documentation

Filter carbohydrate entries

Description

Removes carbohydrate entries that were overwritten by another entry.

Usage

filter_carbs(data_id, max_minutes_overwrite = 2)

Arguments

data_id

A list with all data found for one individual. Filtering is only performed if the carbohydrate and bolus data were cleaned and standardized.

max_minutes_overwrite

Maximum time difference (in minutes) between an overwritten entry and another entry. Default 2 minutes. If NULL, nothing is removed.

Details

In the bolus calculator, carbs may be entered, but the bolus may not be delivered (or cancelled), and the carbs may then be entered again, with a bolus shortly after. Some platforms (e.g. Glooko) export all of these entries.

A carbohydrate entry is removed if

  • its bolus is zero (found via link_id)

  • another carbohydrate entry of the same format (or sharing one, for combined formats such as "glooko/tidepool"), with a different link_id, lies at most max_minutes_overwrite minutes before or after it.

  • it is not flagged as a hypo treatment (is_hypo_treatment).

Slowly absorbed carbohydrates merged during cleaning (linked entries with an estimated_absorption_duration, see clean.glooko) are never removed and do not count as another entry. The zero bolus linked to a removed entry is removed from the bolus data as well.

Value

A list with all data found for one individual, filtered, if necessary. Removed rows are stored in the attribute removed, see removed_entries().

Examples

path <- system.file("extdata", "glooko_example.zip", package = "aidR")
data <- parse_data(id = "1", paths = path)
nrow(data$carbs)

data_filtered <- filter_carbs(data)
nrow(data_filtered$carbs)
removed_entries(data_filtered)

aidR documentation built on Oct. 28, 2026, 5:13 p.m.