make_aux: Align columns of another table as auxiliary predictors

View source: R/synthesize.r

make_auxR Documentation

Align columns of another table as auxiliary predictors

Description

Auxiliary columns condition the synthesis (so cross-table associations survive a later join) but are never censored or written out.

Usage

make_aux(
  src,
  by,
  aux_src,
  aux_spec,
  aux_by,
  cols = NULL,
  key_fun = function(k) toupper(gsub("[^A-Za-z0-9]", "", k))
)

Arguments

src

The table being synthesised (synth_source).

by

Key column of src (internal or on-disk name).

aux_src

The other table (synth_source).

aux_spec

Spec of aux_src.

aux_by

Key column of aux_src.

cols

Columns of aux_src to use (default: all modelled ones).

key_fun

Function normalising keys before matching (e.g. dropping a hyphen so AB-123 matches AB123).

Value

list(raw, roles), rows aligned to src$raw (first match per key).

Examples

df <- data.frame(id = sprintf("AB%03d", 1:60), value = 1:60)
other <- data.frame(id = rev(df$id), code = rep(c(0, 1, NA), 20))
path <- file.path(tempdir(), "make_aux_main.csv")
aux_path <- file.path(tempdir(), "make_aux_other.csv")
utils::write.csv(df, path, row.names = FALSE, na = "")
utils::write.csv(other, aux_path, row.names = FALSE, na = "")
src <- read_source(path)
aux_src <- read_source(aux_path)
aux_spec <- infer_spec(aux_src)
aux <- make_aux(src, by = "id", aux_src = aux_src,
                aux_spec = aux_spec, aux_by = "id", cols = "code")
head(aux$raw)

cellsynth documentation built on Oct. 31, 2026, 1:07 a.m.