napistu.rpy2

napistu.rpy2

This subpackage provides utilities for interacting with R and the rpy2 bridge, including: - Checking rpy2 availability - Importing and caching core and extended rpy2 modules - Handling R session information and error reporting - Decorators for requiring rpy2 and reporting R-related exceptions

All rpy2-related imports are performed lazily and cached, so that the package can be imported even if rpy2 is not installed.

Functions

get_napistu_r_package()

Import and cache the napistu R package using rpy2.

get_rpy2_availability()

Check if rpy2 is available in the current environment.

get_rpy2_core_modules()

Import and cache core rpy2 modules (conversion, default_converter, importr).

get_rpy2_extended_modules()

Import and cache extended rpy2 modules (pandas2ri, pyarrow, rpy2_arrow, etc.).

report_r_exceptions(func)

Decorator to provide helpful error reporting for R-related exceptions.

require_rpy2(func)

Decorator to ensure rpy2 is available before calling the decorated function.

rsession_info()

Report summaries of the R installation found by rpy2.

napistu.rpy2._r_homer_warning() str

Utility function to suggest installation directions for R based on environment.

Returns:

Installation instructions for R in the current environment.

Return type:

str

napistu.rpy2.get_napistu_r_package() Any

Import and cache the napistu R package using rpy2.

Returns:

The imported napistu.r R package object.

Return type:

Any

Raises:

ImportError – If rpy2 or the napistu R package is not available.

napistu.rpy2.get_rpy2_availability() bool

Check if rpy2 is available in the current environment.

Returns:

True if rpy2 is importable, False otherwise.

Return type:

bool

napistu.rpy2.get_rpy2_core_modules() tuple['rpy2.robjects.conversion.Converter', 'rpy2.robjects.conversion.Converter', 'rpy2.robjects.packages.importr']

Import and cache core rpy2 modules (conversion, default_converter, importr).

Returns:

(conversion, default_converter, importr) from rpy2.robjects

Return type:

tuple

Raises:

ImportError – If rpy2 is not available or import fails.

napistu.rpy2.get_rpy2_extended_modules() tuple['rpy2.robjects.pandas2ri', 'pyarrow', 'rpy2_arrow.arrow', 'rpy2.robjects', 'rpy2.robjects.ListVector']

Import and cache extended rpy2 modules (pandas2ri, pyarrow, rpy2_arrow, etc.).

Returns:

(pandas2ri, pyarrow, rpy2_arrow.arrow, ro, ListVector)

Return type:

tuple

Raises:

ImportError – If rpy2 or dependencies are not available or import fails.

napistu.rpy2.report_r_exceptions(func: Callable) Callable

Decorator to provide helpful error reporting for R-related exceptions.

If an exception occurs, logs the error and prints R session info.

napistu.rpy2.require_rpy2(func: Callable) Callable

Decorator to ensure rpy2 is available before calling the decorated function.

Raises:

ImportError – If rpy2 is not available.

napistu.rpy2.rsession_info() None

Report summaries of the R installation found by rpy2.

This function logs the R version, library paths, and session info using rpy2. If R is not available or an error occurs, logs a warning.

Modules

callr

constants

Module for Rpy2 module-specific constants

rids