Checks whether five essential Python packages required to run neural latent variable models
(e.g., LCAnet, LPAnet) are installed in the current Python environment. If any are missing,
the user is interactively prompted to install them via reticulate::py_install().
The targeted packages are:
numpy — Fundamental package for numerical computing in Python.
torch — PyTorch deep learning framework (supports CPU/GPU computation).
matplotlib — 2D plotting and visualization library.
scikit-learn — Machine learning utilities (used here primarily for KMeans initialization).
scipy — Scientific computing and advanced linear algebra routines.
For torch, users can choose between CPU-only or GPU-enabled versions (with CUDA support).
Available CUDA versions are filtered by OS compatibility.
This function is especially useful when deploying models that bridge R and Python via reticulate, ensuring all backend dependencies are met before model execution.
install_python_dependencies()A named list of logical values indicating whether each package was already installed before running this function:
Logical. Was numpy already available?
Logical. Was torch already available?
Logical. Was matplotlib already available?
Logical. Was scikit-learn already available?
Logical. Was scipy already available?
The function performs the following steps for each dependency:
Uses reticulate::py_module_available() to test if the module is importable.
If not available, prints a message describing the package’s purpose.
Prompts the user interactively (via readline) whether to proceed with installation.
For torch, offers CPU/GPU choice and CUDA version selection if GPU is chosen.
Installs the package using reticulate::py_install() with appropriate index URL if needed.
Returns a logical list indicating initial installation status of each package.
Note: This function requires reticulate to be loaded and a valid Python environment configured. It does NOT automatically install reticulate or configure Python — that must be done separately.
library(reticulate)
# Ensure reticulate is loaded and Python is configured
# need python
if (FALSE) {
# Run dependency installer
deps <- install_python_dependencies()
# Check which were missing
print(deps)
}
Run the code above in your browser using DataLab