Skip to contents

Introduction

The slcr package provides two key configuration options that allow you to customize how it interacts with Python and SLC installations. These options give you flexibility to work with different Python environments and SLC installations on your system.

Configuration Options Overview

The package uses R’s options() system to manage configuration. The two main options are:

  1. config.slc.python: Specifies which Python executable to use for creating virtual environments
  2. config.slc.pythonpath: Specifies the path to SLC Python modules

Option 1: config.slc.python

Purpose

The config.slc.python option controls which Python executable is used when creating the virtual environment for the slcr package.

Default Behavior

If not set, the package defaults to using Sys.which("python3"):

# Check current setting
getOption("config.slc.python")
# NULL (if not set)

# See what the default would be
Sys.which("python3")
# "/usr/bin/python3" (example path)

Setting the Option

You can set this option to use a specific Python installation:

# Use a specific Python version
options(config.slc.python = "/usr/bin/python3.11")

# Use a conda environment Python
options(config.slc.python = "/home/user/miniconda3/envs/myenv/bin/python")

# Use a pyenv Python
options(config.slc.python = "/home/user/.pyenv/versions/3.11.0/bin/python")

# Use a system Python in a custom location
options(config.slc.python = "/opt/python/3.11/bin/python")

Common Use Cases

Using a Specific Python Version

# Ensure you're using Python 3.11 specifically
options(config.slc.python = "/usr/bin/python3.11")
setup_python_env()

Using Conda Environments

# Use Python from a conda environment
options(config.slc.python = "/home/user/miniconda3/envs/slc-env/bin/python")
setup_python_env()

# Verify the Python being used
system(paste(getOption("config.slc.python"), "--version"))

Using Virtual Environment Managers

# Using pyenv
options(config.slc.python = "/home/user/.pyenv/versions/3.11.0/bin/python")

# Using poetry (if you have a poetry project)
options(config.slc.python = "/home/user/myproject/.venv/bin/python")

# Using pipenv
options(
  config.slc.python = "/home/user/.local/share/virtualenvs/myproject-abc123/bin/python"
)

Option 2: config.slc.pythonpath

Purpose

The config.slc.pythonpath option specifies where to find the SLC Python modules. This is crucial for the package to locate and import SLC functionality.

Default Behavior

If not set, the package defaults to the standard SLC installation path:

# Check current setting
getOption("config.slc.pythonpath")
# NULL (if not set)

# The default path used internally
"/opt/altair/slc/2026/python"

Setting the Option

You can customize this path for different SLC installations:

# Standard SLC installation (different version)
options(config.slc.pythonpath = "/opt/altair/slc/2025/python")

# Custom SLC installation location
options(config.slc.pythonpath = "/usr/local/slc/python")

# Development or test SLC installation
options(config.slc.pythonpath = "/home/user/slc-dev/python")

# Network-mounted SLC installation
options(config.slc.pythonpath = "/shared/software/slc/2026/python")

Common Use Cases

Multiple SLC Versions

# Switch between SLC versions
options(config.slc.pythonpath = "/opt/altair/slc/2025/python")
conn_2025 <- slc_init()

options(config.slc.pythonpath = "/opt/altair/slc/2026/python")
conn_2026 <- slc_init()

Custom Installation Paths

# SLC installed in a custom location
options(config.slc.pythonpath = "/usr/local/slc/python")

# SLC in a user directory
options(config.slc.pythonpath = "/home/user/software/slc/python")

# SLC on a shared network drive
options(config.slc.pythonpath = "/mnt/shared/slc/python")

Development and Testing

# Use a development version of SLC
options(config.slc.pythonpath = "/home/user/slc-development/python")

# Use a test installation
options(config.slc.pythonpath = "/tmp/slc-test/python")

Configuration Workflows

Setting Options in .Rprofile

For persistent configuration, add options to your .Rprofile:

# In your .Rprofile file
options(
  config.slc.python = "/usr/bin/python3.11",
  config.slc.pythonpath = "/opt/altair/slc/2026/python"
)

Project-Specific Configuration

For project-specific settings, use a project .Rprofile:

# In your project's .Rprofile
if (interactive()) {
  # Development SLC setup
  options(
    config.slc.python = "/home/user/miniconda3/envs/slc-dev/bin/python",
    config.slc.pythonpath = "/home/user/slc-dev/python"
  )

  message("Loaded SLC development configuration")
}

Environment-Specific Configuration

# Production environment
if (Sys.getenv("ENVIRONMENT") == "production") {
  options(
    config.slc.python = "/opt/python/3.11/bin/python",
    config.slc.pythonpath = "/opt/altair/slc/2026/python"
  )
}

# Development environment
if (Sys.getenv("ENVIRONMENT") == "development") {
  options(
    config.slc.python = "/home/user/.pyenv/versions/3.11.0/bin/python",
    config.slc.pythonpath = "/home/user/slc-dev/python"
  )
}

Verification and Troubleshooting

Checking Current Configuration

# Check both options
cat("Python executable:", getOption("config.slc.python", "default"), "\n")
cat("SLC Python path:", getOption("config.slc.pythonpath", "default"), "\n")

# Check if paths exist
python_path <- getOption("config.slc.python")
if (!is.null(python_path) && file.exists(python_path)) {
  cat("Python executable exists: YES\n")
} else {
  cat("Python executable exists: NO\n")
}

slc_path <- getOption("config.slc.pythonpath")
if (!is.null(slc_path) && dir.exists(slc_path)) {
  cat("SLC Python path exists: YES\n")
} else {
  cat("SLC Python path exists: NO\n")
}

Testing Configuration

# Test Python executable
python_exe <- getOption("config.slc.python", Sys.which("python3"))
system(paste(python_exe, "--version"))

# Test SLC path
slc_path <- getOption("config.slc.pythonpath", "/opt/altair/slc/2026/python")
if (dir.exists(slc_path)) {
  list.files(slc_path, pattern = "slc", recursive = TRUE)[1:5]
} else {
  warning("SLC path does not exist: ", slc_path)
}

Common Issues and Solutions

Issue: Python Not Found

# Problem: Python executable doesn't exist
# Solution: Find and set correct Python path
python_candidates <- c(
  "/usr/bin/python3",
  "/usr/bin/python3.11",
  "/usr/local/bin/python3",
  Sys.which("python3"),
  Sys.which("python")
)

for (py in python_candidates) {
  if (file.exists(py)) {
    cat("Found Python:", py, "\n")
    options(config.slc.python = py)
    break
  }
}

Issue: SLC Modules Not Found

# Problem: SLC Python path is incorrect
# Solution: Search for SLC installation
slc_candidates <- c(
  "/opt/altair/slc/2026/python",
  "/opt/altair/slc/2025/python",
  "/usr/local/slc/python",
  "/opt/slc/python"
)

for (slc in slc_candidates) {
  if (dir.exists(slc)) {
    cat("Found SLC installation:", slc, "\n")
    options(config.slc.pythonpath = slc)
    break
  }
}

Issue: Permission Problems

# Problem: No write access to default virtual environment location
# Solution: Use a custom location or fix permissions

# Check current venv location
venv_dir <- file.path(rappdirs::user_data_dir("slcr"), "venvs")
cat("Virtual environment directory:", venv_dir, "\n")

# Test write access
if (dir.exists(dirname(venv_dir))) {
  cat("Parent directory exists\n")
  if (file.access(dirname(venv_dir), mode = 2) == 0) {
    cat("Write access: YES\n")
  } else {
    cat("Write access: NO - check permissions\n")
  }
}

Best Practices

1. Document Your Configuration

Always document why you’re using specific configuration options:

# Configuration for SLC 2025 compatibility project
# Using Python 3.10 to match SLC requirements
options(
  config.slc.python = "/usr/bin/python3.10",
  config.slc.pythonpath = "/opt/altair/slc/2025/python"
)

# Log configuration for debugging
cat("SLC Configuration:\n")
cat("  Python:", getOption("config.slc.python"), "\n")
cat("  SLC Path:", getOption("config.slc.pythonpath"), "\n")

2. Validate Configuration Early

# Validate configuration at the start of your script
validate_slc_config <- function() {
  python_exe <- getOption("config.slc.python", Sys.which("python3"))
  slc_path <- getOption("config.slc.pythonpath", "/opt/altair/slc/2026/python")

  if (!file.exists(python_exe)) {
    stop("Python executable not found: ", python_exe)
  }

  if (!dir.exists(slc_path)) {
    stop("SLC Python path not found: ", slc_path)
  }

  message("Configuration validated successfully")
}

validate_slc_config()

3. Use Environment Variables for Flexibility

# Allow configuration via environment variables
if (Sys.getenv("SLC_PYTHON") != "") {
  options(config.slc.python = Sys.getenv("SLC_PYTHON"))
}

if (Sys.getenv("SLC_PYTHONPATH") != "") {
  options(config.slc.pythonpath = Sys.getenv("SLC_PYTHONPATH"))
}

Conclusion

The config.slc.python and config.slc.pythonpath options provide essential flexibility for working with different Python and SLC installations. By understanding and properly configuring these options, you can:

  • Work with multiple Python versions
  • Use different SLC installations
  • Adapt to various deployment environments
  • Troubleshoot installation and path issues

Remember to validate your configuration early in your workflow and document any custom settings for future reference.