Skip to content

generic

Generic R function caller.

Use call() to invoke R functions by name (including brms functions) when there is no dedicated wrapper in brmspy.brms.

Notes

Executed inside the worker process that hosts the embedded R session.

Functions

sanitised_name(function)

Sanitize a function name for safe R execution.

Parameters:

Name Type Description Default
function str

Function name (optionally namespaced, e.g. "brms::loo").

required

Returns:

Type Description
str

A sanitized name where invalid characters are replaced with underscores, and where leading digits are avoided (except after a namespace).

Examples:

>>> sanitised_name("my-function")
'my_function'
>>> sanitised_name("123func")
'_123func'

call(function, *args, **kwargs)

Call an R function by name with brmspy type conversion.

This is intended as an escape hatch for R/brms functionality that does not yet have a dedicated wrapper.

Parameters:

Name Type Description Default
function str

Function name. If not namespaced, brmspy tries brms::<function> first, then falls back to evaluating the name directly (e.g. "stats::AIC").

required
*args

Positional arguments.

()
**kwargs

Keyword arguments.

{}

Returns:

Type Description
Any

Converted return value.

Examples:

>>> from brmspy import brms
>>> fit = brms.brm("y ~ x", data=df, chains=4)
>>> aic = brms.call("stats::AIC", fit)