Learn R Programming

backports

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:
    .onLoad <- function(libname, pkgname) {
      backports::import(pkgname)
    }
    You can also selectively import functions:
    .onLoad <- function(libname, pkgname) {
      backports::import(pkgname, c("get0", "dir.exists"))
    }
    If you set force = TRUE, the provided functions will get imported, regardless of the R version:
    .onLoad <- function(libname, pkgname) {
      backports::import(pkgname, "hasName", force = TRUE)
    }
  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

  • base::anyNA()
  • base::dir.exists()
  • base::file.size(), base::file.mode() and base::file.mtime()
  • base::lengths()
  • Argument extra_cols for base::file.info()
  • Argument repeated for utils::URLencode
  • base::isNamespaceLoaded()

Backports for R versions prior to 3.3.0

  • base::startsWith() and base::endsWith()
  • base::strrep()
  • base::trimws()
  • Argument type for utils::capture.output()

Backports for R versions prior to 3.4.0

  • base::.valid.factor()
  • utils::hasName()

Backports for R versions prior to 3.5.0

  • base::...length()
  • base::...elt()
  • base::isFALSE()

Backports for R versions prior to 3.6.0

  • base::warningCondition()
  • base::errorCondition()
  • Argument q for base::dQuote() and base::sQuote()
  • tools::vignetteInfo()
  • base::str2lang()
  • base::str2expression()
  • base::asplit()
  • utils::removeSource() with the capability to strip source from language objects.

Backports for R versions prior to 4.0.0

  • base::deparse1()
  • base::list2DF()
  • tools::R_user_dir()
  • Argument classes for base::suppressWarnings() and base::suppressMessages()

Backports for R versions prior to 4.0.1

  • Argument recycle0 for base::paste().
  • Argument recycle0 for base::paste0().

Backports for R versions prior to 4.1.0

  • base::...names()
  • base::.libPaths()

Backports for R versions prior to 4.3.0

  • tools:::print.Rconcordance
  • tools:::as.character.Rconcordance
  • tools::as.Rconcordance
  • tools:::as.Rconcordance.default
  • tools::matchConcordance

Copy Link

Version

Install

install.packages('backports')

Monthly Downloads

677,080

Version

1.5.0

License

GPL-2 | GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

May 23rd, 2024

Functions in backports (1.5.0)

startsWith

Backport of startsWith for R < 3.3.0
warningCondition

Backport of warningCondition and errorCondition for R < 3.6.0
anyNA

Backport of anyNA for R versions < 3.2.0.
stopifnot

Backport of stopifnot for R versions < 4.0.0.
as.Rconcordance

Backport of as.Rconcordance for R < 4.3.0
lengths

Backport of lengths for R < 3.2.0
.libPaths

Backport of .libPaths for R < 4.1.0
file.mode

Backports of wrappers around file.info for R < 3.2.0
file.info

Backport of file.info for R < 3.2.0
strrep

Backport of strrep for R < 3.3.0
str2expression

Backport of str2expression for R < 3.6.0
str2lang

Backport of str2lang for R < 3.6.0
suppressWarnings

Backport of suppressWarnings and suppressMessages for R < 4.0.0
dQuote

Backport of dQuote and sQuote for R < 3.6.0
isNamespaceLoaded

Backport of isNamespaceLoaded for R < 3.2.0
matchConcordance

Backport of matchConcordance for R < 4.3.0
...names

Backport of ...names for R < 4.1.0
paste0

Backport of paste0 for R < 4.0.1
capture.output

Backport of capture.output for R < 3.3.0
endsWith

Backport of endsWith for R < 3.3.0
isTRUE

Backport of isTRUE for R < 3.5.0
print.Rconcordance

Backport of print.Rconcordance for R < 4.3.0
.valid.factor

Backport of .valid.factor for R < 3.4.0
trimws

Backport of trimws for R < 3.3.0
vignetteInfo

Backport of vignetteInfo for R < 3.6.0
R_user_dir

Backport of R_user_dir for R < 4.0.0
URLencode

Backport of URLencode for R < 3.2.0
deparse1

Backport of deparse1 for R < 4.0.0
dir.exists

Backport of dir.exists for R < 3.2.0
import

Import backported functions into your package
isFALSE

Backport of isFALSE for R < 3.4.2
as.Rconcordance.default

Backport of as.Rconcordance.default for R < 4.3.0
list2DF

Backport of list2DF for R < 4.0.0
...elt

Backport of ...elt for R < 3.4.2
as.character.Rconcordance

Backport of as.character.Rconcordance for R < 4.3.0
...length

Backport of ...length for R < 3.4.2
backports-package

backports: Reimplementations of Functions Introduced Since R-3.0.0
asplit

Backport of asplit for R < 3.6.0
get0

Backport of get0 for R < 3.2.0
hasName

Backport of hasName for R < 3.4.0
null_coalesce_operator

Backport of the null-coalescing operator for R < 4.4.0
removeSource

Backport of removeSource for R < 3.6.0
paste

Backport of paste for R < 4.0.1