derive: Define a derived feature

View source: R/derive.R

deriveR Documentation

Define a derived feature

Description

derive() returns a function computing a history-derived feature as of (j, t). Intended to populate Entity$derived_vars and be used by Entity$snapshot*().

Usage

derive(
  name,
  target,
  lookback_t = NULL,
  lookback_j = NULL,
  fn = c("count", "min", "max", "mean", "median", "sd", "iqr", "any", "all"),
  include_current = TRUE,
  force = FALSE,
  na_value = NA,
  clock = "time"
)

Arguments

name

Name of the derived feature.

target

A target created by event() or declare_variable().

lookback_t

Optional numeric lookback window on the time axis. Takes precedence over lookback_j.

lookback_j

Optional integer lookback window in event-index units.

fn

Summary function name. For event() targets, only count, any, and all are supported.

include_current

Logical; include the boundary event at t/j (default TRUE).

force

Logical; if TRUE, return a value when there is no history (default FALSE).

na_value

Value to return when force=TRUE and no history exists (default NA).

clock

Which column in entity$events defines the time axis for lookback_t (default "time").

Value

A function (entity, j, t) -> scalar or NULL.


fluxCore documentation built on Sept. 22, 2026, 5:07 p.m.