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-hookreports 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 withpixi_add()instead, so they're recorded inpixi.tomlandpixi.lock. For a CRAN package that isn't on conda-forge,pixi_add()offers to build it from source. For a package already inpixi.toml, it says to update it withpixi_update()instead.reposis ignored, and other arguments Pixi can't use, such aslib, give an error. Package files and folders are installed withutils::install.packages(), sopixi.tomldoesn't record them. Turn this off withoptions(rpix.install_packages = FALSE).In a package, in an interactive session, rpix notices when
DESCRIPTIONcomes to need packages thatpixi.tomldoesn't have, e.g. afterusethis::use_package()or an edit, and offers to add them withpixi_import_description(). It also says whenDESCRIPTIONno longer lists a package, which you can remove withpixi_remove(). Turn this off withoptions(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=falsein 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())