MyNixOS website logo
Description

Declare when Suggested Packages are Needed.

By adding dependencies to the "Suggests" field of a package's DESCRIPTION file, and then declaring that they are needed within any dependent functionality, it is often possible to significantly reduce the number of "hard" dependencies required by a package. This package provides a minimal way to declare when a suggested package is needed.

suggests: Declare when Suggested Packages are Needed

R-CMD-check Codecov test coverage

By adding dependencies to the "Suggests" field of a package's DESCRIPTION file, and then declaring that they are needed within any dependent functionality, you can often significantly reduce the number of "hard" dependencies (i.e. Depends/Imports) required by your package.

{suggests} aims to make that workflow as minimal and painless as possible, primarily via the need() function, which provides a lightweight, simple, speedy way to prompt your users to install missing suggested packages.

Installation

You can install the development version of {suggests} from GitHub with:

# install.packages("remotes")
remotes::install_github("owenjonesuob/suggests")

Or directly from R-universe:

install.packages("suggests", repos = "https://owenjonesuob.r-universe.dev")

Usage

You can declare that one or more packages are needed for subsequent functionality with need():

read_data <- function(path, clean_names = FALSE) {

  # Call suggests::need() as early as possible, to avoid wasted work
  if (isTRUE(clean_names))
    suggests::need("janitor")

  output <- utils::read.csv(path)

  if (isTRUE(clean_names))
    output <- janitor::clean_names(output)

  output
 }

You can also make sure a minimum version is available by appending >=[version]:

need(
  "dplyr>=1.0.0",
  "tidyr"
)

Additionally, find_pkgs() is a quick-and-dirty diagnostic tool to find dependency usage within top-level expressions (e.g. declared functions) in R scripts within a development package. This can be useful when looking for good candidates for dependencies which could be moved from Imports to Suggests in the DESCRIPTION file.

Given a path, it returns a data frame with one row per distinct top-level expression where a package is used. Packages used in the fewest places are listed first.

find_deps(system.file("demopkg", package = "suggests"))
  package_used              in_file          in_expr
1        stats R/median_first_ten.R median_first_ten
2        tools R/median_first_ten.R median_first_ten
3        utils R/median_first_ten.R median_first_ten

Alternatives

The *_installed() functions from {rlang} provide similar functionality - more flexible, but less lightweight than this package.

You could avoid the need for any package-checking dependencies, if you're willing to write slightly more code yourself! See the Dependencies: In Practice chapter of R Packages (Wickham & Bryan).

Metadata

Version

0.1.0

License

Unknown

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows