### Install TensorFlow Example Source: https://rstudio.github.io/reticulate/dev/articles/python_dependencies.html This example demonstrates how a package like TensorFlow might provide a helper function to install its required Python dependencies. Users can call this function to prepare their environment. ```R library(tensorflow) install_tensorflow() ``` -------------------------------- ### Install Python and Create Virtual Environment Source: https://rstudio.github.io/reticulate/dev/reference/install_python.html Example of installing a specific Python version and creating a virtual environment for it. Supports selecting the latest patch release. ```R library(reticulate) version <- "3.9.12" install_python(version) virtualenv_create("my-environment", version = version) use_virtualenv("my-environment") # There is also support for a ":latest" suffix to select the latest patch release install_python("3.9:latest") # install latest patch available at python.org # select the latest 3.9.* patch installed locally virtualenv_create("my-environment", version = "3.9:latest") ``` -------------------------------- ### Create and Use a Python Virtual Environment Source: https://rstudio.github.io/reticulate/reference/install_python.html Example of installing a specific Python version, creating a virtual environment, and setting it as the active environment. ```R library(reticulate) version <- "3.9.12" install_python(version) virtualenv_create("my-environment", version = version) use_virtualenv("my-environment") ``` -------------------------------- ### Install Python Source: https://rstudio.github.io/reticulate/dev/reference/index.html Install Python on your system using the `install_python()` function. ```r install_python() ``` -------------------------------- ### Install Miniconda with Miniforge Source: https://rstudio.github.io/reticulate/news/index.html Use install_miniconda() to install miniforge, which is now the default instead of miniconda. ```r install_miniconda() ``` -------------------------------- ### Create Virtual Environment with Latest Local Patch Source: https://rstudio.github.io/reticulate/reference/install_python.html Example of creating a virtual environment using the latest locally installed patch release for a specified minor Python version. ```R virtualenv_create("my-environment", version = "3.9:latest") ``` -------------------------------- ### Install Miniconda Source: https://rstudio.github.io/reticulate/dev/reference/install_miniconda.html Use this function to download and install Miniconda. It allows specifying the installation path, whether to update to the latest version, and if re-installation should be forced. ```r install_miniconda(path = miniconda_path(), update = TRUE, force = FALSE) ``` -------------------------------- ### Query Python Configuration Source: https://rstudio.github.io/reticulate/articles/versions.html Use `py_config()` to get information about the currently used Python version and discover other available Python installations. ```r py_config() ``` -------------------------------- ### Install Python Package from Local Filesystem Source: https://rstudio.github.io/reticulate/dev/reference/py_require.html Install a Python package, MarkItDown, from a local directory path. The directory must contain a pyproject.toml or setup.py file. ```string "markitdown@/Users/tomasz/github/microsoft/markitdown/packages/markitdown/" ``` -------------------------------- ### install_miniconda Source: https://rstudio.github.io/reticulate/reference/install_miniconda.html Downloads and installs the Miniconda installer to manage Python environments. It allows specifying the installation path, whether to update to the latest version, and whether to force re-installation. ```APIDOC ## Function: install_miniconda ### Description Downloads the Miniconda installer and uses it to install Miniconda. This function helps in setting up a Python environment managed by Miniconda. ### Usage ```R install_miniconda(path = miniconda_path(), update = TRUE, force = FALSE) ``` ### Arguments * **path** (string) - The location where Miniconda is (or should be) installed. The Miniconda installer does not support paths containing spaces. Defaults to the path returned by `miniconda_path()`. * **update** (boolean) - If TRUE, updates to the latest version of Miniconda after installation. Defaults to TRUE. * **force** (boolean) - If TRUE, forces re-installation even if Miniconda is already installed at the specified path. Defaults to FALSE. ### Details For arm64 builds of R on macOS, `install_miniconda()` will use binaries from miniforge instead. ### Note If binary incompatibilities arise between R and Miniconda, `install_python()` can be used to perform a scripted build and installation of Python from sources. ### See Also Other miniconda-tools: `miniconda_uninstall()`, `miniconda_update()` ``` -------------------------------- ### Install SciPy using pip (Shell) Source: https://rstudio.github.io/reticulate/articles/python_packages.html Installs the SciPy package into the system-level Python installation using pip from the shell. ```shell # install into system level Python $ sudo pip install SciPy ``` -------------------------------- ### Install Python Package from Git Tag Source: https://rstudio.github.io/reticulate/dev/reference/py_require.html Install a Python package, Ruff, from a specific Git tag. ```string "git+https://github.com/astral-sh/ruff@v0.2.0" ``` -------------------------------- ### R-lib Actions setup for R package testing Source: https://rstudio.github.io/reticulate/dev/articles/package.html A basic GitHub Actions workflow setup for testing R packages, including setting up R and R dependencies. ```yaml - uses: r-lib/actions/setup-r@v2 - uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: rcmdcheck - uses: r-lib/actions/check-r-package@v2 ``` -------------------------------- ### Install Python Package from Git with Subdirectory Source: https://rstudio.github.io/reticulate/dev/reference/py_require.html Install a Python package, MarkItDown, from a specific Git branch, specifying a subdirectory within the repository. ```string "markitdown@git+https://github.com/microsoft/markitdown.git@main#subdirectory=packages/markitdown" ``` -------------------------------- ### Install Python Package from Git Commit Source: https://rstudio.github.io/reticulate/dev/reference/py_require.html Install a Python package, Ruff, from a specific Git commit hash. ```string "git+https://github.com/astral-sh/ruff@1fadefa67b26508cc59cf38e6130bde2243c929d" ``` -------------------------------- ### Install Python Package from Git Branch Source: https://rstudio.github.io/reticulate/dev/reference/py_require.html Install a Python package, Ruff, from a specific Git branch. ```string "git+https://github.com/astral-sh/ruff@main" ``` -------------------------------- ### install_miniconda Source: https://rstudio.github.io/reticulate/dev/reference/index.html Installs Miniconda on the system. ```APIDOC ## install_miniconda ### Description Install Miniconda. ### Method Not specified (assumed to be a function call within an R environment). ### Parameters None explicitly documented. ### Request Example ```R install_miniconda() ``` ### Response None explicitly documented. ``` -------------------------------- ### Install Development Version from GitHub Source: https://rstudio.github.io/reticulate/articles/python_packages.html Installs a development version of the 'markitdown' package directly from a GitHub repository using `py_require`. The package is specified with its GitHub URL and a subdirectory. ```R # Install the 'markitdown' package from GitHub. py_require("markitdown@git+https://github.com/microsoft/markitdown.git@main#subdirectory=packages/markitdown") ``` -------------------------------- ### Install Development Version from Local Filesystem Source: https://rstudio.github.io/reticulate/articles/python_packages.html Installs a development version of the 'markitdown' package from a local filesystem path using `py_require`. This is useful for testing local changes before publishing. ```R # Install it from the local filesystem. py_require("markitdown@/Users/tomasz/github/microsoft/markitdown/packages/markitdown/") ``` -------------------------------- ### install_miniconda Source: https://rstudio.github.io/reticulate/reference/index.html Installs Miniconda, a minimal installer for Conda. This function simplifies the process of setting up Miniconda for environment management. ```APIDOC ## install_miniconda ### Description Install Miniconda. ### Method Not applicable (R function) ### Endpoint Not applicable (R function) ### Parameters * **path** (character) - Optional - The directory where Miniconda should be installed. ### Request Example ```R install_miniconda(path = "~/miniconda") ``` ### Response * **None** - This function installs Miniconda. ``` -------------------------------- ### py_install Source: https://rstudio.github.io/reticulate/dev/reference/index.html Installs Python packages into the current environment. ```APIDOC ## py_install ### Description Installs Python packages. ### Method Not specified (assumed to be a function call within an R environment). ### Parameters None explicitly documented. ### Request Example ```R py_install("package_name") ``` ### Response None explicitly documented. ``` -------------------------------- ### install_python Source: https://rstudio.github.io/reticulate/reference/install_python.html Downloads and installs a specified version of Python using pyenv and pyenv-win. It supports installing specific versions, listing available versions, forcing re-installation, and building optimized versions. ```APIDOC ## install_python ### Description Installs a specified version of Python using the pyenv and pyenv-win projects. This function allows for version selection, listing available versions, forcing re-installation, and building optimized Python interpreters. ### Method ``` install_python( version = "3.12:latest", list = FALSE, force = FALSE, optimized = TRUE ) ``` ### Arguments * **version** (string) - The version of Python to install. Supports a ":latest" suffix to select the latest patch release for a given minor version (e.g., "3.9:latest"). * **list** (boolean) - If TRUE, lists the set of available Python versions. * **force** (boolean) - If TRUE, forces re-installation even if the requested version of Python is already installed. * **optimized** (boolean) - If TRUE (default), the installation will be optimized for performance but take longer. Only applicable on macOS and Linux. If FALSE, Python is built with basic shared options. ### Details It is recommended to create Python virtual environments using Python installations from `install_python()`. For example: ```R library(reticulate) version <- "3.9.12" install_python(version) virtualenv_create("my-environment", version = version) use_virtualenv("my-environment") # Install latest patch for 3.9 install_python("3.9:latest") # Create virtualenv with latest 3.9 patch locally virtualenv_create("my-environment", version = "3.9:latest") ``` ### Note On macOS and Linux, Python is built from source. Pre-installing system dependencies can speed up the process. See https://github.com/pyenv/pyenv/wiki#suggested-build-environment for commands. If `optimized = TRUE`, Python is built with: ``` PYTHON_CONFIGURE_OPTS="--enable-shared --enable-optimizations --with-lto" PYTHON_CFLAGS="-march=native -mtune=native" ``` If `optimized = FALSE`, Python is built with: ``` PYTHON_CONFIGURE_OPTS=--enable-shared ``` On Windows, prebuilt installers from https://www.python.org are used. ``` -------------------------------- ### install_miniconda Source: https://rstudio.github.io/reticulate/dev/reference/install_miniconda.html Downloads and installs the Miniconda package manager. It allows specifying the installation path, whether to update to the latest version, and whether to force a re-installation if Miniconda is already present. ```APIDOC ## Function: install_miniconda ### Description Downloads the Miniconda installer and uses it to install Miniconda. ### Usage ``` install_miniconda(path = miniconda_path(), update = TRUE, force = FALSE) ``` ### Arguments * **path** (string) - The location where Miniconda is (or should be) installed. Note that the Miniconda installer does not support paths containing spaces. See `miniconda_path` for more details on the default path used by `reticulate`. * **update** (boolean) - Update to the latest version of Miniconda after installation? * **force** (boolean) - Force re-installation if Miniconda is already installed at the requested path? ### Details For arm64 builds of R on macOS, `install_miniconda()` will use binaries from miniforge instead. ### Note If you encounter binary incompatibilities between R and Miniconda, a scripted build and installation of Python from sources can be performed by `install_python()` ### See also Other miniconda-tools: `miniconda_uninstall()`, `miniconda_update()` ``` -------------------------------- ### py_install Source: https://rstudio.github.io/reticulate/dev/reference/py_install.html Installs Python packages into a specified virtual environment or Conda environment. Users can control the installation method, environment name, and whether to use pip. ```APIDOC ## Function: py_install ### Description Installs Python packages into a virtual environment or Conda environment. ### Usage ```R py_install( packages, envname = NULL, method = c("auto", "virtualenv", "conda"), conda = "auto", python_version = NULL, pip = FALSE, ..., pip_ignore_installed = ignore_installed, ignore_installed = FALSE ) ``` ### Arguments * **packages** (vector) - A vector of Python packages to install. * **envname** (string | NULL) - The name, or full path, of the environment in which Python packages are to be installed. Defaults to the `RETICULATE_PYTHON_ENV` variable or the `r-reticulate` environment. * **method** (string) - Installation method. Options are "auto", "virtualenv", or "conda". "auto" attempts to find a suitable method. Note: "virtualenv" is not available on Windows. * **conda** (string) - The path to a `conda` executable. Defaults to "auto" for automatic detection. * **python_version** (string | NULL) - The requested Python version. Ignored when using a Python virtual environment. * **pip** (boolean) - If TRUE, use `pip` for package installation (relevant for Conda environments). * **...** - Additional arguments passed to `conda_install()` or `virtualenv_install()`. * **pip_ignore_installed** (boolean) - Whether pip should ignore previously installed versions of packages. If TRUE, installs the latest versions of all dependencies. * **ignore_installed** (boolean) - Alias for `pip_ignore_installed`. `pip_ignore_installed` takes precedence. ### Details On Linux and OS X, "virtualenv" is the default method unless unavailable, in which case "conda" is used. On Windows, "conda" is always used. ### See Also `conda_install()`, `virtualenv_install()` ``` -------------------------------- ### install_python Source: https://rstudio.github.io/reticulate/dev/reference/install_python.html Downloads and installs a specified version of Python using pyenv and pyenv-win. It supports installing specific versions, listing available versions, forcing re-installation, and building optimized interpreters. ```APIDOC ## install_python ### Description Installs a specified version of Python using the pyenv and pyenv-win projects. This function allows users to manage Python installations directly from R. ### Method install_python( version = "3.12:latest", list = FALSE, force = FALSE, optimized = TRUE ) ### Parameters #### Arguments - **version** (string) - The version of Python to install. Defaults to "3.12:latest". Supports a ":latest" suffix to select the latest patch release. - **list** (boolean) - If TRUE, lists the set of available Python versions. - **force** (boolean) - If TRUE, forces re-installation even if the requested version of Python is already installed. - **optimized** (boolean) - If TRUE (default), installation will take significantly longer but should result in a faster Python interpreter. Only applicable on macOS and Linux. ### Details It is recommended to create Python virtual environments using the copies of Python installed by `install_python()`. For example: ```R library(reticulate) version <- "3.9.12" install_python(version) virtualenv_create("my-environment", version = version) use_virtualenv("my-environment") # There is also support for a ":latest" suffix to select the latest patch release install_python("3.9:latest") # install latest patch available at python.org # select the latest 3.9.* patch installed locally virtualenv_create("my-environment", version = "3.9:latest") ``` On macOS and Linux, this function builds Python from source, which may take a few minutes. Pre-installing system dependencies can speed up the process. On Windows, prebuilt installers from python.org are used. If `optimized = TRUE`, Python is built with: ``` PYTHON_CONFIGURE_OPTS="--enable-shared --enable-optimizations --with-lto" PYTHON_CFLAGS="-march=native -mtune=native" ``` If `optimized = FALSE`, Python is built with: ``` PYTHON_CONFIGURE_OPTS=--enable-shared ``` ``` -------------------------------- ### Install Python Function Signature Source: https://rstudio.github.io/reticulate/dev/reference/install_python.html The signature for the `install_python` function, showing available arguments. ```R install_python( version = "3.12:latest", list = FALSE, force = FALSE, optimized = TRUE ) ``` -------------------------------- ### Define TensorFlow Installation Function Source: https://rstudio.github.io/reticulate/dev/articles/python_dependencies.html This function installs the TensorFlow Python package into a specified virtual environment, defaulting to 'r-tensorflow'. It can optionally create the environment if it doesn't exist. ```R install_tensorflow <- function(..., envname = "r-tensorflow") { reticulate::py_install("tensorflow", envname = envname, ...) } ``` -------------------------------- ### Install Development Version of a Python Package Source: https://rstudio.github.io/reticulate/dev/articles/python_packages.html Installs a development version of a Python package directly from a GitHub repository or a local filesystem path. Useful when a fix is available in development but not yet published. ```R # Install the 'markitdown' package from GitHub. py_require("markitdown@git+https://github.com/microsoft/markitdown.git@main#subdirectory=packages/markitdown") # Install it from the local filesystem. py_require("markitdown@/Users/tomasz/github/microsoft/markitdown/packages/markitdown/") ``` -------------------------------- ### conda_install Source: https://rstudio.github.io/reticulate/dev/reference/conda-tools.html Installs packages into a conda environment. ```APIDOC ## conda_install ### Description Installs packages into a conda environment. ### Usage __``` conda_install( envname = NULL, packages, forge = TRUE, channel = character(), pip = FALSE, pip_options = character(), pip_ignore_installed = FALSE, conda = "auto", python_version = NULL, additional_create_args = character(), additional_install_args = character(), ... ) ``` ### Arguments * `envname` (character) - The name of, or path to, a conda environment. * `packages` (character vector) - A character vector, indicating package names which should be installed or removed. Use `==` to request the installation of a specific version of a package. * `forge` (logical) - Boolean; include the conda-forge repository? * `channel` (character vector) - An optional character vector of conda channels to include. When specified, the `forge` argument is ignored. If you need to specify multiple channels, including the conda forge, you can use `c("conda-forge", ) * `pip` (logical) - Boolean; use `pip` for package installation? By default, packages are installed from the active conda channels. * `pip_options` (character vector) - An optional character vector of additional command line arguments to be passed to `pip`. Only relevant when `pip = TRUE`. * `pip_ignore_installed` (logical) - Ignore already-installed versions when using pip? (defaults to `FALSE`). Set this to `TRUE` so that specific package versions can be installed even if they are downgrades. The `FALSE` option is useful for situations where you don't want a pip install to attempt an overwrite of a conda binary package (e.g. SciPy on Windows which is very difficult to install via pip due to compilation requirements). * `conda` (character) - The path to a `conda` executable. Use `"auto"` to allow `reticulate` to automatically find an appropriate `conda` binary. See **Finding Conda** and `conda_binary()` for more details. * `python_version` (character) - The version of Python to be installed. Set this if you'd like to change the version of Python associated with a particular conda environment. * `additional_create_args` (character vector) - An optional character vector of additional arguments to use in the call to `conda create`. * `additional_install_args` (character vector) - An optional character vector of additional arguments to use in the call to `conda install`. * `...` - Optional arguments, reserved for future expansion. ``` -------------------------------- ### conda_install Source: https://rstudio.github.io/reticulate/reference/conda-tools.html Installs packages into a conda environment. ```APIDOC ## conda_install ### Description Installs packages into a conda environment. ### Method Not applicable (R function) ### Endpoint Not applicable (R function) ### Parameters #### Arguments - **envname** (character) - The name of, or path to, a conda environment. - **packages** (character vector) - A character vector, indicating package names which should be installed or removed. Use `==` to request the installation of a specific version of a package. - **forge** (boolean) - Boolean; include the conda-forge repository? - **channel** (character vector) - An optional character vector of conda channels to include. When specified, the `forge` argument is ignored. If you need to specify multiple channels, including the conda forge, you can use `c("conda-forge", ) - **pip** (boolean) - Boolean; use `pip` for package installation? By default, packages are installed from the active conda channels. - **pip_options** (character vector) - An optional character vector of additional command line arguments to be passed to `pip`. Only relevant when `pip = TRUE`. - **pip_ignore_installed** (boolean) - Ignore already-installed versions when using pip? (defaults to `FALSE`). Set this to `TRUE` so that specific package versions can be installed even if they are downgrades. The `FALSE` option is useful for situations where you don't want a pip install to attempt an overwrite of a conda binary package (e.g. SciPy on Windows which is very difficult to install via pip due to compilation requirements). - **conda** (character) - The path to a `conda` executable. Use `"auto"` to allow `reticulate` to automatically find an appropriate `conda` binary. See **Finding Conda** and `conda_binary()` for more details. - **python_version** (character) - The version of Python to be installed. Set this if you'd like to change the version of Python associated with a particular conda environment. - **additional_create_args** (character vector) - An optional character vector of additional arguments to use in the call to `conda create`. - **additional_install_args** (character vector) - An optional character vector of additional arguments to use in the call to `conda install`. - **...** (reserved for future expansion). ``` -------------------------------- ### Get, Set, and Delete items from Python dict Source: https://rstudio.github.io/reticulate/dev/reference/py_get_item.html Demonstrates how to get, set, and delete items from a Python dictionary using R syntax. Assigning NULL to an item effectively deletes it. ```R x <- r_to_py(list(abc = "xyz")) #' # R expression | Python expression # -------------------- | ----------------- x["abc"] # x["abc"] x["abc"] <- "123" # x["abc"] = "123" x["abc"] <- NULL # del x["abc"] x["abc"] <- py_none() # x["abc"] = None ``` -------------------------------- ### Install Python Dependencies into a Project-Specific Environment Source: https://rstudio.github.io/reticulate/dev/articles/python_dependencies.html Create a virtual environment in the project directory and install Python dependencies for multiple R packages into it. reticulate will automatically discover this environment. ```R envname <- "./venv" tensorflow::install_tensorflow(envname = envname) pysparklyr::install_pyspark(envname = envname) ``` -------------------------------- ### virtualenv_install Source: https://rstudio.github.io/reticulate/dev/reference/virtualenv-tools.html Installs Python packages into an existing virtual environment. ```APIDOC ## virtualenv_install ### Description Installs Python packages into an existing virtual environment. ### Usage ```R virtualenv_install( envname = NULL, packages = NULL, ignore_installed = FALSE, pip_options = character(), requirements = NULL, ..., python_version = NULL ) ``` ### Parameters * `envname` (NULL) - The name of the virtual environment to install packages into. * `packages` (NULL) - A character vector of Python packages to install. * `ignore_installed` (boolean) - If TRUE, ignore already installed packages. * `pip_options` (character) - Additional options to pass to pip. * `requirements` (character) - Path to a requirements file specifying packages to install. * `...` - Additional arguments to pass to the installation command. * `python_version` (character) - The Python version of the environment. ``` -------------------------------- ### virtualenv_install Source: https://rstudio.github.io/reticulate/reference/virtualenv-tools.html Installs Python packages into an existing virtual environment. ```APIDOC ## virtualenv_install ### Description Installs Python packages into an existing virtual environment. ### Usage ```R virtualenv_install( envname = NULL, packages = NULL, ignore_installed = FALSE, pip_options = character(), requirements = NULL, ..., python_version = NULL ) ``` ### Arguments * `envname`: Name of the virtual environment. * `packages`: A character vector of Python packages to install. * `ignore_installed`: If TRUE, ignores already installed packages. * `pip_options`: Additional options to pass to pip. * `requirements`: Path to a `requirements.txt` file specifying packages to install. * `...`: Additional arguments. * `python_version`: The Python version of the environment (used for finding the correct Python executable). ``` -------------------------------- ### py_install Source: https://rstudio.github.io/reticulate/reference/py_install.html Installs Python packages into a specified virtual environment or Conda environment. It supports automatic detection of installation methods, custom conda paths, and version specification. ```APIDOC ## py_install ### Description Installs Python packages into a virtual environment or Conda environment. ### Usage ```R py_install( packages, envname = NULL, method = c("auto", "virtualenv", "conda"), conda = "auto", python_version = NULL, pip = FALSE, ..., pip_ignore_installed = ignore_installed, ignore_installed = FALSE ) ``` ### Arguments * **packages** (vector) - A vector of Python packages to install. * **envname** (string | NULL) - The name, or full path, of the environment in which Python packages are to be installed. Defaults to the active environment or `r-reticulate`. * **method** (string) - Installation method. Defaults to "auto", which automatically finds a suitable method. Can be forced to "virtualenv" or "conda". Note: "virtualenv" is not available on Windows. * **conda** (string) - The path to a `conda` executable. Defaults to "auto" for automatic detection. * **python_version** (string | NULL) - The requested Python version. Ignored when using a Python virtual environment. * **pip** (boolean) - Whether to use `pip` for package installation (relevant for Conda environments). * **...** - Additional arguments passed to `conda_install()` or `virtualenv_install()`. * **pip_ignore_installed** (boolean) - Whether pip should ignore previously installed versions of packages. If TRUE, installs the latest versions of all dependencies. * **ignore_installed** (boolean) - Alias for `pip_ignore_installed`. `pip_ignore_installed` takes precedence. ### Details On Linux and OS X, "virtualenv" is the default method unless unavailable, in which case "conda" is used. On Windows, "conda" is always used. ### See Also `conda_install()`, `virtualenv_install()` ``` -------------------------------- ### Get Conda Version Source: https://rstudio.github.io/reticulate/dev/reference/conda-tools.html Returns the version of the conda installation. Use 'auto' to let reticulate find it. ```r conda_version(conda = "auto") ``` -------------------------------- ### Get a Virtual Environment Starter Source: https://rstudio.github.io/reticulate/reference/virtualenv-tools.html Use `virtualenv_starter` to find a suitable Python executable for creating a virtual environment. The `version` argument can specify a desired Python version. ```R virtualenv_starter(version = NULL, all = FALSE) ``` -------------------------------- ### Install Python package using pip Source: https://rstudio.github.io/reticulate/dev/reference/py_exe.html Use `py_exe()` to get the Python executable path and then invoke `pip` to install a Python package like numpy. This demonstrates direct interaction with Python modules from R. ```r system2(py_exe(), c("-m", "pip", "install", "numpy")) ``` -------------------------------- ### Run ruff tool with help argument Source: https://rstudio.github.io/reticulate/dev/reference/uv_run_tool.html Example of running the 'ruff' tool with the '--help' argument to display its usage information. ```R uv_run_tool("ruff", "--help") ``` -------------------------------- ### miniconda_path Source: https://rstudio.github.io/reticulate/dev/reference/index.html Retrieves the installation path of Miniconda. ```APIDOC ## miniconda_path ### Description Path to Miniconda. ### Method Not specified (assumed to be a function call within an R environment). ### Parameters None explicitly documented. ### Request Example ```R miniconda_path() ``` ### Response None explicitly documented. ``` -------------------------------- ### virtualenv_starter Source: https://rstudio.github.io/reticulate/reference/virtualenv-tools.html Provides a starter Python executable for creating virtual environments. ```APIDOC ## virtualenv_starter ### Description Provides a starter Python executable for creating virtual environments. ### Usage ```R virtualenv_starter(version = NULL, all = FALSE) ``` ### Arguments * `version`: The desired Python version. * `all`: If TRUE, returns all available starter Python executables. ``` -------------------------------- ### Get Default Miniconda Path Source: https://rstudio.github.io/reticulate/dev/reference/miniconda_path.html Call this function to retrieve the default path to the Miniconda installation. This is useful for understanding where reticulate expects to find Miniconda. ```r miniconda_path() ``` -------------------------------- ### virtualenv_starter Source: https://rstudio.github.io/reticulate/dev/reference/virtualenv-tools.html Provides a starter Python executable for creating virtual environments. ```APIDOC ## virtualenv_starter ### Description Provides a starter Python executable for creating virtual environments. ### Usage ```R virtualenv_starter(version = NULL, all = FALSE) ``` ### Parameters * `version` (NULL) - The desired Python version. * `all` (boolean) - If TRUE, return all available starter Python executables. ``` -------------------------------- ### py_exe() Source: https://rstudio.github.io/reticulate/reference/py_exe.html Retrieves the path to the Python executable that reticulate has been configured to use. If Python has already been initialized, reticulate will choose the currently-active copy of Python. This is useful for interacting with Python via subprocesses, for example, to install packages with pip. ```APIDOC ## py_exe() ### Description Get the path to the Python executable that `reticulate` has been configured to use. If Python has already been initialized, then `reticulate` will choose the currently-active copy of Python. ### Usage ``` py_exe() ``` ### Value The path to the Python executable `reticulate` has been configured to use. ### Details This can occasionally be useful if you'd like to interact with Python (or its modules) via a subprocess; for example you might choose to install a package with `pip`: ``` system2(py_exe(), c("-m", "pip", "install", "numpy")) ``` and so you can also have greater control over how these modules are invoked. ``` -------------------------------- ### Get Documentation for Python Objects Source: https://rstudio.github.io/reticulate/reference/index.html Use `py_help()` to access the documentation for Python objects. ```r py_help(my_python_object) ``` -------------------------------- ### Install Python Packages with py_install() Source: https://rstudio.github.io/reticulate/dev/articles/package.html Use `reticulate::py_install()` to install Python packages. By default, packages are installed in the currently active Python installation. This function provides a high-level interface for dependency management. ```R library(reticulate) py_install("scipy") ``` -------------------------------- ### macOS/Linux Build Dependencies Source: https://rstudio.github.io/reticulate/dev/reference/install_python.html Example command to pre-install system dependencies for building Python from sources on macOS. ```shell brew install openssl readline sqlite3 xz zlib tcl-tk@8 libb2 ``` -------------------------------- ### virtualenv_create, virtualenv_install, virtualenv_remove, virtualenv_list, virtualenv_root, virtualenv_python, virtualenv_exists, virtualenv_starter Source: https://rstudio.github.io/reticulate/dev/reference/index.html Provides an interface for managing Python virtual environments, including creation, installation, removal, listing, and accessing environment details. ```APIDOC ## Virtual Environment Interface ### Description Interface to Python Virtual Environments. ### Methods - `virtualenv_create()`: Creates a new virtual environment. - `virtualenv_install()`: Installs packages into a virtual environment. - `virtualenv_remove()`: Removes a virtual environment. - `virtualenv_list()`: Lists available virtual environments. - `virtualenv_root()`: Gets the root directory for virtual environments. - `virtualenv_python()`: Gets the Python executable path for a virtual environment. - `virtualenv_exists()`: Checks if a virtual environment exists. - `virtualenv_starter()`: Gets the starter for a virtual environment. ### Parameters Parameters for each function are not explicitly documented in the source. ### Request Example ```R # Example for creating a virtual environment virtualenv_create("myenv") ``` ### Response None explicitly documented for individual functions. ``` -------------------------------- ### Run httpie tool specifying the package Source: https://rstudio.github.io/reticulate/dev/reference/uv_run_tool.html Illustrates how to specify a Python package ('httpie') to provide the command ('http') using the 'from' argument. ```R uv_run_tool("http", from = "httpie") ``` -------------------------------- ### Install Python Packages from PyPI Source: https://rstudio.github.io/reticulate/articles/python_packages.html Installs the 'pandas' Python package using the `py_install` function. Packages are installed into a virtualenv or Conda environment named 'r-reticulate' by default. ```R library(reticulate) py_install("pandas") ``` -------------------------------- ### Run a tool with a complex command string Source: https://rstudio.github.io/reticulate/dev/reference/uv_run_tool.html Shows how to execute a command that includes arguments directly within the tool string, such as 'kaggle competitions download -c dogs-vs-cats'. ```R uv_run_tool("kaggle competitions download -c dogs-vs-cats") ``` -------------------------------- ### Get Length of Python Object Source: https://rstudio.github.io/reticulate/dev/reference/index.html Get the length of a Python object using `py_len()`. ```r py_len() ``` -------------------------------- ### Determine Python Version for Virtual Environment Creation Source: https://rstudio.github.io/reticulate/dev/reference/virtualenv-tools.html Use `virtualenv_starter` to find available Python versions for creating virtual environments. The `all` argument can be set to `TRUE` to list all available versions. ```R virtualenv_starter(version = "3.9") virtualenv_starter(all = TRUE) ``` -------------------------------- ### Install Python Packages Source: https://rstudio.github.io/reticulate/dev/reference/py_install.html Use `py_install()` to install specified Python packages into a virtual or Conda environment. The function supports automatic environment detection or explicit specification of environment names and installation methods. ```R py_install( packages, envname = NULL, method = c("auto", "virtualenv", "conda"), conda = "auto", python_version = NULL, pip = FALSE, ..., pip_ignore_installed = ignore_installed, ignore_installed = FALSE ) ``` -------------------------------- ### miniconda_path Source: https://rstudio.github.io/reticulate/reference/index.html Returns the installation path of Miniconda. This function is useful for locating the Miniconda installation directory. ```APIDOC ## miniconda_path ### Description Path to Miniconda. ### Method Not applicable (R function) ### Endpoint Not applicable (R function) ### Parameters None ### Request Example ```R miniconda_path() ``` ### Response * **character** - The path to the Miniconda installation. ``` -------------------------------- ### Create and Use a Virtual Environment Source: https://rstudio.github.io/reticulate/articles/python_packages.html Demonstrates creating a virtual environment named 'r-reticulate', installing the 'scipy' package within it, and then importing 'scipy' in R. Reticulate automatically discovers packages in the specified environment. ```R library(reticulate) # create a new environment virtualenv_create("r-reticulate") # install SciPy virtualenv_install("r-reticulate", "scipy") # import SciPy (it will be automatically discovered in "r-reticulate") scipy <- import("scipy") ``` -------------------------------- ### Get Name of Python Type Source: https://rstudio.github.io/reticulate/dev/reference/index.html Get the name of a Python type object using `nameOfClass()`. ```r nameOfClass(__) ``` -------------------------------- ### Run markitdown tool and capture output Source: https://rstudio.github.io/reticulate/dev/reference/uv_run_tool.html Demonstrates running the 'markitdown' tool with a file path as an argument and capturing its standard output. The output is returned as a character vector. ```R uv_run_tool("markitdown", shQuote(file.path(R.home("doc"), "NEWS.pdf")), stdout = TRUE) ``` -------------------------------- ### Get Unique Identifier for Python Object Source: https://rstudio.github.io/reticulate/dev/reference/index.html Get a unique identifier for a Python object using `py_id()`. ```r py_id() ``` -------------------------------- ### Install TensorFlow with Environment Reset Source: https://rstudio.github.io/reticulate/dev/articles/python_dependencies.html This enhanced installation function for TensorFlow includes logic to remove and recreate the 'r-tensorflow' environment if it already exists, ensuring a clean installation. It uses reticulate's functions to check for and remove virtual environments. ```R install_tensorflow <- function(..., envname = "r-tensorflow", new_env = identical(envname, "r-tensorflow")) { if(new_env && virtualenv_exists(envname)) virtualenv_remove(envname) py_install(packages = "tensorflow", envname = envname, ...) } ``` -------------------------------- ### Run httpie tool with version constraint and capture output Source: https://rstudio.github.io/reticulate/dev/reference/uv_run_tool.html Shows running the 'http' command from 'httpie' with a version constraint ('httpie<3.2.4') and capturing its standard output. This is useful for checking tool versions or specific outputs. ```R uv_run_tool("http", "--version", from = "httpie<3.2.4", stdout = TRUE) ``` -------------------------------- ### use_miniconda Source: https://rstudio.github.io/reticulate/reference/use_python.html Select a Miniconda environment to be used by reticulate. For `use_miniconda()`, the only conda installation searched is the one installed by `install_miniconda()`. ```APIDOC ## use_miniconda ### Description Select a Miniconda environment to be used by reticulate. For `use_miniconda()`, the only conda installation searched is the one installed by `install_miniconda()`. ### Usage ```R use_miniconda(condaenv = NULL, required = NULL) ``` ### Arguments * **condaenv** (string | NULL) - The conda environment to use. For `use_miniconda()`, the only conda installation searched is the one installed by `install_miniconda()`. * **required** (boolean | NULL) - Is the requested copy of Python required? If `TRUE`, an error will be emitted if the requested copy of Python does not exist. If `FALSE`, the request is taken as a hint only, and scanning for other versions will still proceed. A value of `NULL` (the default), is equivalent to `TRUE`. ``` -------------------------------- ### Python: Create and Display a 3D Array (Fortran Order) Source: https://rstudio.github.io/reticulate/dev/articles/arrays.html Demonstrates creating a 3D NumPy array in Python using `np.reshape` with 'F' (Fortran) order to match R's column-major layout. ```python import numpy as np np.reshape(np.arange(1,25), (4,3,2), "F") ``` -------------------------------- ### use_miniconda Source: https://rstudio.github.io/reticulate/dev/reference/use_python.html Select the Miniconda installation for reticulate to use. This function specifically targets the Conda installation created by `install_miniconda()`. ```APIDOC ## Function: use_miniconda ### Description Select the Miniconda installation for reticulate to use. This function specifically targets the Conda installation created by `install_miniconda()`. ### Usage ``` use_miniconda(condaenv = NULL, required = NULL) ``` ### Arguments * **condaenv** (character) - The conda environment to use. For `use_miniconda()`, the only conda installation searched is the one installed by `install_miniconda()`. * **required** (logical) - Is the requested copy of Python required? If TRUE, an error will be emitted if the requested copy of Python does not exist. If FALSE, the request is taken as a hint only, and scanning for other versions will still proceed. A value of NULL (the default) is equivalent to TRUE. ``` -------------------------------- ### Get Python Object Type Name Source: https://rstudio.github.io/reticulate/reference/index.html Use `nameOfClass()` to get the name of the Python type for a Python object. ```r nameOfClass(my_python_object) ``` -------------------------------- ### conda_list, conda_create, conda_clone, conda_export, conda_remove, conda_install, conda_binary, conda_exe, conda_version, conda_update, conda_python, conda_search, condaenv_exists Source: https://rstudio.github.io/reticulate/dev/reference/index.html A suite of tools for managing Conda environments and packages, including listing, creating, cloning, exporting, removing, installing, and querying Conda information. ```APIDOC ## Conda Tools ### Description Tools for managing Conda environments and packages. ### Methods - `conda_list()`: Lists Conda environments. - `conda_create()`: Creates a Conda environment. - `conda_clone()`: Clones a Conda environment. - `conda_export()`: Exports a Conda environment. - `conda_remove()`: Removes a Conda environment. - `conda_install()`: Installs packages into a Conda environment. - `conda_binary()`: Gets the Conda binary path. - `conda_exe()`: Gets the Conda executable path. - `conda_version()`: Gets the Conda version. - `conda_update()`: Updates Conda packages or environments. - `conda_python()`: Gets the Python executable path for a Conda environment. - `conda_search()`: Searches for Conda packages. - `condaenv_exists()`: Checks if a Conda environment exists. ### Parameters Parameters for each function are not explicitly documented in the source. ### Request Example ```R # Example for listing Conda environments conda_list() ``` ### Response None explicitly documented for individual functions. ``` -------------------------------- ### Get String Representation of Python Object Source: https://rstudio.github.io/reticulate/reference/index.html Use `py_repr()` or `py_str()` to get the string representation of a Python object. ```r py_repr(my_python_object) ``` ```r py_str(my_python_object) ``` -------------------------------- ### Run pycowsay tool Source: https://rstudio.github.io/reticulate/dev/reference/uv_run_tool.html Example of running the 'pycowsay' command-line tool with an argument. Arguments are quoted using shQuote to handle shell special characters. ```R uv_run_tool("pycowsay", shQuote("hello from reticulate")) ``` -------------------------------- ### Get String Representation of Python Object Source: https://rstudio.github.io/reticulate/dev/reference/index.html Get the string representation of a Python object using `py_repr()` or `py_str()`. ```r py_repr() py_str() ``` -------------------------------- ### py_install Source: https://rstudio.github.io/reticulate/reference/index.html Installs Python packages. This function allows users to directly install specified Python packages into the R environment. ```APIDOC ## py_install ### Description Installs Python packages. ### Method Not applicable (R function) ### Endpoint Not applicable (R function) ### Parameters * **packages** (character or list of character) - Required - The names of the Python packages to install. ### Request Example ```R py_install("numpy") py_install(c("pandas", "scikit-learn")) ``` ### Response * **None** - This function performs an action and does not return a value. ``` -------------------------------- ### Pre-downloading Python dependencies in CI Source: https://rstudio.github.io/reticulate/dev/articles/package.html Example of a GitHub Actions workflow that pre-downloads Python dependencies in a separate step for cleaner CI logs, then runs R package checks. ```yaml - uses: r-lib/actions/setup-r@v2 with: r-version: release - uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: rcmdcheck local::. - run: | library(mypackage) # <-- declare requirements in .onLoad() reticulate::py_config() # <-- resolves the ephemeral python environment - uses: r-lib/actions/check-r-package@v2 # The ephemeral python environment from previous step is reused from cache. ``` -------------------------------- ### Update Miniconda Source: https://rstudio.github.io/reticulate/dev/reference/miniconda_update.html Call this function to update your Miniconda installation to the latest version. The 'path' argument specifies the installation directory. ```r miniconda_update(path = miniconda_path()) ``` -------------------------------- ### Install Packages into Conda Environment Source: https://rstudio.github.io/reticulate/dev/reference/conda-tools.html Installs packages into a conda environment, optionally using pip or specifying additional arguments. ```r conda_install( envname = NULL, packages, forge = TRUE, channel = character(), pip = FALSE, pip_options = character(), pip_ignore_installed = FALSE, conda = "auto", python_version = NULL, additional_create_args = character(), additional_install_args = character(), ... ) ``` -------------------------------- ### R: Create and Display a 3D Array Source: https://rstudio.github.io/reticulate/dev/articles/arrays.html Demonstrates creating a 3D array in R using `array()` and displays its contents, showing R's default column-major ordering. ```r array(1:24, c(4,3,2)) ``` -------------------------------- ### Get Length of Python Object Source: https://rstudio.github.io/reticulate/reference/index.html Use `py_len()` to get the length of a Python object (e.g., list, string, tuple). ```r py_len(my_python_object) ``` -------------------------------- ### Create and Manage Virtual Environments Source: https://rstudio.github.io/reticulate/dev/articles/python_packages.html Demonstrates creating a virtual environment, installing a package within it, and then importing that package in R. Ensures a specific virtualenv is utilized by reticulate. ```R library(reticulate) # create a new environment virtualenv_create("r-reticulate") # install SciPy virtualenv_install("r-reticulate", "scipy") # import SciPy (it will be automatically discovered in "r-reticulate") scipy <- import("scipy") ``` ```R library(reticulate) # indicate that we want to use a specific virtualenv use_virtualenv("r-reticulate") ``` -------------------------------- ### Get Unique Identifier for Python Object Source: https://rstudio.github.io/reticulate/reference/index.html Use `py_id()` to get the unique identifier (memory address) of a Python object. ```r py_id(my_python_object) ``` -------------------------------- ### Expand %system Command Output in repl_python() Source: https://rstudio.github.io/reticulate/news/index.html Use unpacking with the %system magic command in repl_python() to assign output to multiple variables. Fixed issue with '!!' in string literals. ```python a, b = %system echo 'hello world' print(a) print(b) ``` -------------------------------- ### Install SciPy using conda (Shell) Source: https://rstudio.github.io/reticulate/articles/python_packages.html Installs the SciPy package into the active Conda environment using the conda command from the shell. ```shell # install into active Conda environment $ conda install SciPy ``` -------------------------------- ### Use Miniconda Installation Source: https://rstudio.github.io/reticulate/reference/use_python.html Specifically use the Miniconda installation managed by reticulate. This is useful for ensuring a consistent Python environment managed by reticulate itself. ```R use_miniconda(condaenv = "myenv") ``` -------------------------------- ### Run ruff format tool on Python files Source: https://rstudio.github.io/reticulate/dev/reference/uv_run_tool.html Demonstrates using 'uv_run_tool' to run the 'ruff format' command on all Python files in the current directory. Uses shQuote and Sys.glob for argument construction. ```R uv_run_tool("ruff format", shQuote(Sys.glob("**.py"))) ``` -------------------------------- ### Install reticulate Package Source: https://rstudio.github.io/reticulate/articles/rstudio_ide.html Install the reticulate package using the install.packages() function. This is a prerequisite for using RStudio's IDE tools for reticulate. ```r install.packages("reticulate") ``` -------------------------------- ### Get Unique Identifier for Python Object Source: https://rstudio.github.io/reticulate/dev/reference/py_id.html Get a globally unique identifier for a Python object. In the current implementation of CPython, this is the memory address of the object. ```r py_id(object) ```