Skip to contents

Make R that was started directly from a Pixi environment, as IDEs such as Positron and VS Code do, behave like R started with pixi run R. Called from the project's .Rprofile, which use_pixi() sets up.

  • If Pixi didn't activate the environment, its environment variables are set, as pixi shell-hook reports them. Some packages need them, e.g. to find their data.

  • Your personal library is removed from .libPaths(), and the project's own library added if it exists. Other libraries, such as temporary ones that devtools adds, are kept.

  • install.packages() adds packages with pixi_add() instead, so they're recorded in pixi.toml and pixi.lock. For a CRAN package that isn't on conda-forge, pixi_add() offers to build it from source. For a package already in pixi.toml, it says to update it with pixi_update() instead. repos is ignored, and other arguments Pixi can't use, such as lib, give an error. Package files and folders are installed with utils::install.packages(), so pixi.toml doesn't record them. Turn this off with options(rpix.install_packages = FALSE).

  • In a package, in an interactive session, rpix notices when DESCRIPTION comes to need packages that pixi.toml doesn't have, e.g. after usethis::use_package() or an edit, and offers to add them with pixi_import_description(). It also says when DESCRIPTION no longer lists a package, which you can remove with pixi_remove(). Turn this off with options(rpix.watch_description = FALSE).

  • If R isn't the R of a Pixi environment in this project, nothing changes; in an interactive session you get a hint instead. In RStudio, it also offers to reopen the project in a new RStudio with the environment's R, and to close this one. Turn that off with RPIX_OFFER_SWITCH=false in your .Renviron.

  • If the project also has renv, e.g. because RStudio's New Project set it up, it says so: renv and Pixi both manage the project's packages.

  • If the project was moved or copied, Pixi's activation cache, which has the old location, is removed, and environments that need reinstalling are named.

It never fails: problems are reported as messages.

Usage

pixi_activate(path = getwd(), quiet = !interactive())

Arguments

path

The project. Defaults to the working directory, which is where R reads .Rprofile from.

quiet

If TRUE, show no messages.

Value

A list, invisibly: activated is TRUE if environment variables were set, and lib_paths the new library paths, or NULL if they weren't changed.

Examples

if (FALSE) { # \dontrun{
pixi_activate()
} # }