Skip to contents

Splits subjects into chunks sized to fit in available RAM, solves each chunk, and writes output to parquet (or rds) files. Returns an rxSolveOom object that lazily reads chunks on demand.

Usage

rxSolveChunked(
  object,
  params = NULL,
  events = NULL,
  inits = NULL,
  ...,
  chunkSize,
  seed = NULL,
  parallel = 0L
)

Arguments

object

rxode2 model

params

model parameters

events

event table or rxEtFile

inits

initial conditions

...

additional arguments passed to rxControl()

chunkSize

number of subjects per chunk (auto-computed from free RAM if omitted)

seed

random seed (sets before solving if not NULL)

parallel

number of mirai daemons for parallel chunk solving (0 = serial)

Value

An rxSolveOom object

Details

The storage/query engine used by the resulting rxSolveOom object is controlled by the rxode2.oom.backend option:

"auto"

(default) DuckDB if installed, else arrow, else rds.

"duckdb"

lazy DuckDB SQL queries over arrow-written parquet.

"arrow"

arrow parquet reads/writes, no DuckDB.

"rds"

plain rds files, no arrow or DuckDB.

A requested engine that is not installed silently degrades (duckdb \(\to\) arrow \(\to\) rds).

Examples

# \donttest{
mod <- function() {
  ini({
    k <- 0.1
  })
  model({
    d/dt(A) <- -k * A
  })
}
# 6 subjects solved 3 at a time; chunks are written to tempdir()
s <- rxSolveChunked(mod, et(amt = 100) |> et(0:24) |> et(id = 1:6), chunkSize = 3)
#>  
#>  
#> ℹ parameter labels from comments are typically ignored in non-interactive mode
#> ℹ Need to run with the source intact to parse comments
#>  
#>  
dim(s)
#> duckdb keeps downloaded extensions and secrets in a temporary directory:
#> ℹ /tmp/Rtmpfg2ztF/duckdb
#> This is removed when the R session ends.
#> • Extensions are re-downloaded each session.
#> • Secrets are lost.
#> ℹ Run duckdb(shared_home = TRUE) (or create ~/.duckdb) to keep them (suitable for most users).
#> ℹ Run duckdb(shared_home = FALSE) to accept the temporary directory (and silence this message).
#> ℹ See ?duckdb_storage for details and alternatives.
#> [1] 150   3
head(as.data.frame(s))
#>   id time         A
#> 1  1    0 100.00000
#> 2  1    1  90.48383
#> 3  1    2  81.87316
#> 4  1    3  74.08191
#> 5  1    4  67.03206
#> 6  1    5  60.65310
# }