Fit a model asynchronously

Description

Submits [ferx_fit](ferx_fit.qmd) to a background process and returns immediately, leaving the R session free. Call [ferx_collect](ferx_collect.qmd)on the returned handle to block-wait for the result and see live trace progress.

Usage

ferx_fit_async(model, data = NULL, ..., tail_n = 6L, poll_interval = 0.5)

# S3 method for ferx_job
print(x, ...)

Arguments

  • model, data, ...: Forwarded to [ferx_fit](ferx_fit.qmd). See its documentation for the full argument list.
  • tail_n: Integer. Number of recent trace rows to keep visible per poll in [ferx_collect](ferx_collect.qmd). Default 6.
  • poll_interval: Numeric. Seconds between polls in [ferx_collect](ferx_collect.qmd). Default 0.5.
  • x: A ferx_job handle returned by ferx_fit_async().

Details

In RStudio the fit is submitted via rstudioapi::jobRunScript() and appears in the Jobs pane. In Positron, plain R, or any other interactive session it uses callr::r_bg(). Both backends return the same ferx_job handle and the same ferx_collect() call retrieves the result. The function forces optimizer_trace = TRUE internally so it has a parseable progress channel. When you did not explicitly request the trace, the temp CSV is deleted after ferx_collect() returns; pass optimizer_trace = TRUE explicitly to keep it.

Non-interactive use

When called in a non-interactive session, ferx_fit_async() silently falls back to [ferx_fit](ferx_fit.qmd) since background jobs only add value in an interactive console.

Seealso

Other fitting: [ferx_check_init](ferx_check_init.qmd)(), [ferx_collect](ferx_collect.qmd)(), [ferx_fit](ferx_fit.qmd)(), [ferx_inits_from_nca](ferx_inits_from_nca.qmd)(), [ferx_sir](ferx_sir.qmd)()

Concept

fitting

Value

A ferx_job handle. Pass it to [ferx_collect](ferx_collect.qmd)to retrieve the ferx_fit result. In non-interactive sessions (Rscript, knitr, batch mode) the function falls back to a synchronous [ferx_fit](ferx_fit.qmd) call and returns the result directly.

Examples

ex <- ferx_example("warfarin")
handle <- ferx_fit_async(ex$model, ex$data, method = "focei")
# R prompt is free immediately
print(handle)
fit <- ferx_collect(handle)
summary(fit)