Skip to contents

Creates/uses a named virtual environment and installs Python requirements (pandas, requests, lxml, bs4, playwright), then installs Playwright Chromium.

Usage

downballot_install_python(
  envname = "downballotR",
  python = NULL,
  reinstall = FALSE,
  install_chromium = TRUE,
  quiet = FALSE
)

Arguments

envname

Name of the virtualenv to create/use.

python

Path to a python executable to use when creating the env (optional).

reinstall

If TRUE, reinstall packages even if already installed.

install_chromium

If TRUE, install Playwright Chromium browser. In interactive sessions, the user will be prompted for explicit consent before the download (~100-200 MB) begins. In non-interactive sessions, the function will error if Chromium is missing; set install_chromium = FALSE to suppress this.

quiet

If TRUE, suppress progress messages.

Value

Called for side effects. Returns invisible(TRUE) on success, or invisible(FALSE) if the user declines the Chromium download.

Details

Python must already be installed on your system before calling this function. downballot_install_python() creates a virtual environment using an existing Python interpreter — it does not install Python itself. If Python is not found, reticulate will error with a message about being unable to create a virtualenv.

  • Windows: Install Python from https://www.python.org/downloads/. Make sure to check "Add Python to PATH" during installation.

  • macOS: Python 3 is available via Xcode Command Line Tools (xcode-select --install) or https://www.python.org/downloads/.

  • Linux: Install via your package manager, e.g. sudo apt install python3 python3-venv (Debian/Ubuntu) or sudo dnf install python3 (Fedora/RHEL).

If the environment already exists and all required packages are present, the function prints a message and returns without doing work (unless Chromium is missing and install_chromium = TRUE). In all cases, it attempts to initialize reticulate to the selected interpreter for this session.