Skip to contents

Detaches the r-mosaic Python environment from the current R session. This function provides guided instructions for properly detaching and restarting R to use a different Python environment.

Usage

detach_mosaic_env(restart = FALSE)

Arguments

restart

Logical. If TRUE and in RStudio, automatically restart the R session. Default: FALSE (just provide instructions).

Value

Invisible NULL. If restart = TRUE and in RStudio, the session will restart and this function will not return.

Details

Due to reticulate's design, once Python is initialized in an R session, it cannot be switched to a different environment without restarting R.

This function:

  • Unsets the RETICULATE_PYTHON environment variable

  • Provides instructions for restarting R

  • Optionally triggers automatic restart (RStudio only)

After detaching:

  • The RETICULATE_PYTHON variable is cleared

  • The current Python session remains active (cannot be changed)

  • Detaching lasts only for this session: in a new session, library(MOSAIC) sets RETICULATE_PYTHON to r-mosaic again whenever it is unset and r-mosaic exists

  • To use a different Python, set RETICULATE_PYTHON before loading MOSAIC

See also

attach_mosaic_env for attaching the environment, check_python_env for checking the current environment

Examples

if (FALSE) { # \dontrun{
# Detach and get restart instructions
detach_mosaic_env()

# Detach and automatically restart (RStudio only)
detach_mosaic_env(restart = TRUE)

# To use a different Python after detaching:
# 1. detach_mosaic_env()
# 2. Restart R
# 3. Sys.setenv(RETICULATE_PYTHON = "/path/to/other/python")
# 4. library(MOSAIC)  # Will use your specified Python
} # }