backports

CRAN_Status_Badge R-CMD-check Download Stats

This package provides backports of functions which have been introduced in one of the base packages in R version 3.0.1 or later. The backports are conditionally exported in order to let R resolve the function name to either the implemented backport, or the respective base version, if available. Package developers can make use of new functions or arguments by selectively importing specific backports to support older installations.

Usage

Interactively

Attach the namespace via library(backports).

Note that it is crucial that backports is build against the currently running R version. Do not ignore these kind of warnings for this package.

In packages

  1. Add backports to your DESCRIPTION under Imports.
  2. Add or modify the function .onLoad() (see here) to call the import() function of backports:

    You can also selectively import functions:

    If you set force = TRUE, the provided functions will get imported, regardless of the R version:

  3. [Optional] Set Depends in your DESCRIPTION to require R (>= 3.0.0).

Importing backports from utils or tools

Backports for functions which are not in the base require additional steps. Usually, you need to to import those functions in the package NAMESPACE. However, this is only possible if such a function really exists, and yields a warning during R CMD check for older versions. There are three possibilities to deal with this:

  1. Completely import the namespaces instead of selectively importing them, e.g. use import(utils) instead of importFrom(utils, hasName) in your NAMESPACE file.
  2. Force-import the function (see above) so that you always use the backport instead of the implementation shipped with R, even for the most recent version of R.
  3. Use a conditional import in your NAMESPACE file, e.g.

    if (getRversion() >= "3.4.0") {
      importFrom(utils, hasName)
    } else {
      importFrom(backports, hasName)
    }

    Note that the braces {} are necessary in the NAMESPACE file, even though they wouldn’t be for regular R code, and that you might get a warning for including backports in the Imports: section of your DESCRIPTION file if you never end up using it.

Backports for R versions prior to 3.2.0

Backports for R versions prior to 3.3.0

Backports for R versions prior to 3.4.0

Backports for R versions prior to 3.5.0

Backports for R versions prior to 3.6.0

Backports for R versions prior to 4.0.0

Backports for R versions prior to 4.0.1

Backports for R versions prior to 4.1.0

Backports for R versions prior to 4.3.0