Manage/install
Manage brmspy runtimes and R environments.
This module defines the surface returned by brmspy.brms.manage().
The file is safe to import in the main Python process (no top-level
rpy2.robjects imports). In normal use these methods are invoked through the
manage() context, and the actual work executes in the worker process that
hosts the embedded R session.
Example:
env = "mrp"
if not brms.environment_exists(env):
with brms.manage(environment_name=env) as ctx:
ctx.install_brms(use_prebuilt=True)
ctx.install_rpackage("MCMCglmm")
else:
brms.environment_activate(env)
Notes
- Use the context manager to ensure the worker (and its embedded R session) is started with the desired environment configuration.
- Calling these methods directly in the main process is unsupported and may reintroduce the same stability issues that the worker isolation is designed to avoid.
Classes¶
ManageModule
¶
Management surface returned by brmspy.brms.manage().
The returned object is a proxy that executes these methods inside the worker process. Use it to install brms/toolchains, manage R packages in the active environment, and query basic runtime state.
Notes
The worker process must be able to run R and (depending on the installation mode) may require an OS toolchain for compiling packages / CmdStan.
Functions¶
install_runtime(*, install_rtools=False)
staticmethod
¶
Install the prebuilt brmspy runtime bundle.
This is a convenience wrapper around install_brms(use_prebuilt=True).
It downloads (if necessary) a precompiled runtime and optionally activates it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
install_rtools
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
Path or None
|
Path to the installed runtime directory (prebuilt mode). Returns |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no compatible prebuilt runtime exists for the current platform. |
Examples:
install_brms(*, use_prebuilt=False, install_rtools=False, brms_version=None, cmdstanr_version=None, install_rstan=True, install_cmdstanr=True, rstan_version=None, activate=True)
staticmethod
¶
Install brms and its toolchain dependencies.
In traditional mode (use_prebuilt=False), this installs into the active R
library (typically the active brmspy environment) and may build CmdStan from
source.
In prebuilt mode (use_prebuilt=True), this downloads a brmspy runtime
bundle (R packages + CmdStan) and can activate it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_prebuilt
|
bool
|
If |
False
|
install_rtools
|
bool
|
If |
False
|
brms_version
|
str or None
|
Version spec for the brms R package (traditional mode only). |
None
|
cmdstanr_version
|
str or None
|
Version spec for cmdstanr (traditional mode only). |
None
|
install_rstan
|
bool
|
If |
True
|
install_cmdstanr
|
bool
|
If |
True
|
rstan_version
|
str or None
|
Version spec for rstan (traditional mode only). |
None
|
activate
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
Path or None
|
If |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If installation fails (for example missing toolchain, or no compatible prebuilt runtime exists). |
Examples:
Prebuilt (fast) install:
>>> from brmspy import brms
>>> with brms.manage(environment_name="default") as ctx:
... ctx.install_brms(use_prebuilt=True)
Traditional (R installs + builds CmdStan):
install_rpackage(name, version=None, repos_extra=None)
staticmethod
¶
Install an R package into the active environment library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
R package name (e.g. |
required |
version
|
str or None
|
Optional version spec. |
None
|
repos_extra
|
list[str] or None
|
Extra repositories to add (for example R-universe URLs). |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Notes
This installs into the active R library path (usually the brmspy environment library), not into the system R library tree.
Examples:
uninstall_rpackage(name)
staticmethod
¶
Uninstall an R package from the active library paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
R package name. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Notes
Package unloading/removal can be OS-dependent (especially on Windows where DLLs may be locked). This function makes a best effort.
Examples:
import_rpackages(*names)
staticmethod
¶
Import (load) one or more R packages into the worker's embedded R session.
This does not install packages. Use install_rpackage() first if needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*names
|
str
|
One or more package names. |
()
|
Returns:
| Type | Description |
|---|---|
None
|
|
Examples:
is_rpackage_loaded(name)
staticmethod
¶
Check whether an R package is loaded in the current R session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
R package name. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
get_rpackage_version(name)
staticmethod
¶
Get installed version of an R package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
R package name. |
required |
Returns:
| Type | Description |
|---|---|
str or None
|
Installed version string, or |
is_rpackage_installed(name)
staticmethod
¶
Check whether an R package is installed in the active library paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
R package name. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
get_lib_paths()
staticmethod
¶
Get the current R .libPaths() search paths.
Returns:
| Type | Description |
|---|---|
list[str]
|
R library search paths (highest priority first). |
get_cmdstan_path()
staticmethod
¶
Get the current CmdStan path configured in cmdstanr.
Returns:
| Type | Description |
|---|---|
str or None
|
CmdStan directory path, or |