Package 'piamenv'

Title: Package environment support for PIAM
Description: Enables easier management of package environments, based on renv and conda.
Authors: Pascal Sauer [aut, cre], Tonn Rüter [aut]
Maintainer: Pascal Sauer <[email protected]>
License: LGPL-3
Version: 0.7.1
Built: 2025-03-25 16:20:19 UTC
Source: https://github.com/pik-piam/piamenv

Help Index


piamenv: Package environment support for PIAM

Description

Enables easier management of package environments, based on renv and conda.

Author(s)

Maintainer: Pascal Sauer [email protected]

Authors:

See Also

Useful links:


archiveRenv

Description

Writes a new <timestamp>_renv.lock based on the current package environment into renv::project()/renv/archive.

Usage

archiveRenv()

Value

Invisibly, the absolute path to the created lockfile.

Author(s)

Pascal Sauer


Check Dependencies

Description

Check if package requirements specified in the given DESCRIPTION are met.

Usage

checkDeps(
  descriptionFile = ".",
  dependencyTypes = c("Depends", "Imports", "LinkingTo"),
  action = "stop"
)

Arguments

descriptionFile

Path to a DESCRIPTION file or a path that belongs to a source package project. If /DEPENDENCIES exists that will be used instead.

dependencyTypes

The types of dependencies to check. Must be a subset of c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances").

action

Action to take on unmet dependencies:

  • "stop": Issue an error with the unmet dependencies. (Default.)

  • "warn": Issue a warning with the unmet dependencies.

  • "note": Issue a message with the unmet dependencies.

  • "pass": Do nothing, just return invisibly.

  • "ask": Ask the user whether to auto-fix missing dependencies. Requires an active renv. Will also write renv.lock. If no active renv is found, stops instead.

Value

Invisibly, a named list of strings indicating whether each package requirement is met ("TRUE") or not, in which case the reason is stated.

Author(s)

Pascal Sauer, Michaja Pehl

Examples

checkDeps(system.file("DESCRIPTION", package = "piamenv"))

condaInit

Description

Determine initialization commands to make conda available

Usage

condaInit(how = "", log = NULL, verbose = 0)

Arguments

how

Method to activate conda if not found (e.g., "pik-cluster")

log

Path to log file or NULL to use stdout

verbose

Verbosity level (0 for silent, higher for more verbose)

Value

List containing 'setup' and 'teardown' commands, and environment variables ('env').


condaRun

Description

Run a command in a specified conda environment with given environment variables.

Usage

condaRun(
  cmd,
  path,
  env = c(),
  init = list(setup = "", teardown = ""),
  log = NULL,
  verbose = 0
)

Arguments

cmd

Command to run in the conda environment

path

Path to the conda environment

env

Named vector of environment variables to set, i.e., c("VAR0" = "value0", "VAR1" = "value1")

init

List containing 'setup' and 'teardown' commands to run before and after the command

log

Path to log file or NULL to use stdout

verbose

Verbosity level (0 for silent, higher for more verbose).

Value

Invisible NULL


Fix Dependencies

Description

Automatically install package versions as suggested by piamenv::checkDeps into an renv.

Usage

fixDeps(
  ask = FALSE,
  requirementMet = checkDeps(action = if (ask) "note" else "pass")
)

Arguments

ask

Whether to ask before fixing dependencies.

requirementMet

The output of piamenv::checkDeps.

Value

Invisibly, the return value of renv::install.

Author(s)

Pascal Sauer


installDeps

Description

Install dependencies, identified by renv::dependencies for a given path, into the current renv.

Usage

installDeps(path)

Arguments

path

The path to scan for dependencies.

Author(s)

Pascal Sauer


restoreRenv

Description

Restores the current renv to the state described in the given lockfile. If multiple lockfiles are given, ask the user which one to restore.

Usage

restoreRenv(
  lockfile = Sys.glob(c("output/*/*renv.lock", "renv/archive/*renv.lock"))
)

Arguments

lockfile

One or more paths to lockfiles. The default value assumes an output folder with run folders containing renv.lock files, and/or an renv/archive folder with renv.lock files.

Value

Invisibly, the return value of renv::restore.

Author(s)

Pascal Sauer


Revert Development Versions of Packages

Description

All PIK-PIAM packages in the current renv that are development versions, i.e. that have a non-zero fourth version number component (e.g. ⁠0.4.3.9001⁠), are reverted to the highest version lower than the development versions (e.g. ⁠0.4.3⁠).

Usage

revertDevelopmentVersions()

Value

Invisibly the return value of renv::install().


showUpdates

Description

Print available updates of the given packages.

Usage

showUpdates(packages = piamPackages())

Arguments

packages

A character vector of package names.

Value

Invisibly, a data.frame as returned by utils::old.packages


stopIfLoaded

Description

Throw an error if any of the given packages is loaded.

Usage

stopIfLoaded(updatedPackage)

Arguments

updatedPackage

One or more names of packages that were just updated.

Details

This is useful after updating packages. If any of the updated packages was loaded before the update R might crash when trying to lazy load a function from the updated package.

Author(s)

Pascal Sauer

Examples

## Not run: 
updates <- piamenv::fixDeps()
piamenv::stopIfLoaded(names(updates))

updates <- piamenv::updateRenv()
piamenv::stopIfLoaded(names(updates))

## End(Not run)

updateRenv

Description

Update all PIK-PIAM packages in the current renv, write renv.lock into archive.

Usage

updateRenv(exclude = NULL)

Arguments

exclude

vector of packages not to be updated

Value

Invisibly, the return value of renv::update.

Author(s)

Pascal Sauer