scr_run: Run the selection for several targets straight from the...

View source: R/select.R

scr_runR Documentation

Run the selection for several targets straight from the database

Description

For each target: fetches the table, runs scr_select() and writes the deliverables. A failure on one target is recorded and the loop continues.

Usage

scr_run(
  con,
  table,
  targets,
  config = scr_config(),
  drop = character(),
  date_col = config$oot_date_col,
  event_level = NULL,
  sample_frac = 1,
  max_rows = NULL,
  export = NULL
)

Arguments

con

A DBI connection, from scr_connect().

table

Table name, with an optional {target}.

targets

Vector with the names of the target columns.

config

An object from scr_config(), used for every target.

drop

Columns that are never candidates.

date_col

Date column of the out-of-time split, passed on to scr_select(). Defaults to config$oot_date_col; an explicit NULL forces a random stratified split.

event_level

Passed on to scr_select().

sample_frac

Sampling fraction. A scalar or a list named by target.

max_rows

Row cap per target. NULL switches it off.

export

Root output directory; each target writes to a subdirectory.

Value

An scr_runset object: a named list of scr_result (or, for the targets that failed, a list with error).

Table convention

table accepts the {target} placeholder, replaced by the lower-case target name. Without the placeholder, the same table is used for every target.

See Also

scr_compare() and scr_core() to read the run set.

Other portfolio: scr_compare(), scr_core(), scr_runset

Examples


con <- scr_connect(driver = RSQLite::SQLite(), dbname = ":memory:")
d <- scr_demo; d$ref_date <- as.character(d$ref_date)   # SQLite has no Date type
DBI::dbWriteTable(con, "dtm", d)
cfg <- scr_config(verbose = FALSE, nthread = 1, use_ranger = FALSE,
                  xgb_rounds = 60, n_boot = 20)
rs <- scr_run(con, "dtm", targets = c("default", "churn"), config = cfg,
              drop = c("id", "ref_date", "default", "churn"))
rs
scr_compare(rs)
DBI::dbDisconnect(con)


scorecraft documentation built on Dec. 6, 2026, 1:09 a.m.