SetupPyEnv: Create or Use Python Environment with Required Packages

View source: R/22_SetupPyEnv.R

SetupPyEnvR Documentation

Create or Use Python Environment with Required Packages

Description

Sets up a Python environment with specified packages. This function can create new environments or reuse existing ones, supporting both Conda and venv environment types. It ensures all required dependencies are properly installed and verified.

Default method for unsupported environment types. Throws an informative error with supported environment types.

Usage

SetupPyEnv(env_type = c("conda", "venv"), ...)

## Default S3 method:
SetupPyEnv(env_type = c("conda", "venv"), ...)

Arguments

env_type

Character string specifying the type of Python environment to create or use. One of: "conda", "venv".

...

Additional parameters passed to specific environment methods.

Details

This function provides a comprehensive solution for Python environment management in R projects, particularly for machine learning workflows requiring TensorFlow. Key features include:

  • Environment Creation: Automatically creates new environments or reuses existing ones with the same name

  • Package Management: Installs specified Python packages with version pinning support

  • Verification: Validates environment setup and package installations

  • Flexible Methods: Supports different backend methods for environment creation (reticulate vs system calls)

The function uses S3 method dispatch to handle different environment types, allowing for extensible support of additional environment managers in the future.

Value

A data frame containing verification results for the environment setup, including installation status of all required packages. Invisibly returns the verification results.

See Also

reticulate::conda_create(), reticulate::virtualenv_create() for underlying environment creation functions.

Examples

## Not run: 
# Setup a Conda environment with default parameters
SetupPyEnv("conda")

# Setup a venv environment
SetupPyEnv("venv")

## End(Not run)


SigBridgeRUtils documentation built on Sept. 29, 2026, 5:09 p.m.