io
I/O helpers for brmspy.
This module contains helpers for:
- loading example datasets from R packages
- saving/loading R objects via saveRDS / readRDS
Notes
These functions are executed inside the worker process that hosts the embedded R session.
Classes¶
Functions¶
get_data(dataset_name, **kwargs)
¶
Load an R dataset and return it as a pandas DataFrame.
This is a thin wrapper around R's data() that loads the object
into the R global environment and converts it to a
:class:pandas.DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
str
|
Name of the dataset as used in R (e.g. |
required |
**kwargs
|
Additional keyword arguments forwarded to R's |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Dataset converted to a pandas DataFrame. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the dataset is not found in the R global environment after
calling |
RuntimeError
|
If conversion from the R object to a pandas DataFrame fails. |
See Also
get_brms_data
Convenience wrapper for datasets from the brms package.
get_brms_data(dataset_name, **kwargs)
¶
Load an example dataset from the R brms package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
str
|
Dataset name (for example |
required |
**kwargs
|
Forwarded to R |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Dataset converted to a DataFrame. |
Examples:
save_rds(object, file, **kwargs)
¶
Save an R object to an .rds file via R saveRDS().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object
|
RListVectorExtension or ProxyListSexpVector
|
Object to save. If you pass a |
required |
file
|
str
|
Output path. |
required |
**kwargs
|
Forwarded to R |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
|
Examples:
read_rds_raw(file, **kwargs)
¶
Load an R object from an .rds file via R readRDS().
This returns the raw R object handle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
Input path. |
required |
**kwargs
|
Forwarded to R |
{}
|
Returns:
| Type | Description |
|---|---|
ListSexpVector
|
Raw R object. |
Examples:
read_rds_fit(file, **kwargs)
¶
Load a saved brms model from an .rds file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
Input path containing a saved brmsfit. |
required |
**kwargs
|
Forwarded to R |
{}
|
Returns:
| Type | Description |
|---|---|
FitResult
|
|
Examples: