Type: | Package |
Title: | Reimplementations of Functions Introduced Since R-3.0.0 |
Version: | 1.5.0 |
Maintainer: | Michel Lang <michellang@gmail.com> |
Description: | Functions introduced or changed since R v3.0.0 are re-implemented in this package. 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. |
URL: | https://github.com/r-lib/backports |
BugReports: | https://github.com/r-lib/backports/issues |
License: | GPL-2 | GPL-3 |
NeedsCompilation: | yes |
ByteCompile: | yes |
Depends: | R (≥ 3.0.0) |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.1 |
Packaged: | 2024-05-23 11:56:25 UTC; michel |
Author: | Michel Lang |
Repository: | CRAN |
Date/Publication: | 2024-05-23 12:30:02 UTC |
backports: Reimplementations of Functions Introduced Since R-3.0.0
Description
Functions introduced or changed since R v3.0.0 are re-implemented in this package. 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.
Author(s)
Maintainer: Michel Lang michellang@gmail.com (ORCID)
Authors:
Duncan Murdoch murdoch.duncan@gmail.com
R Core Team
See Also
Useful links:
Backport of ...elt for R < 3.4.2
Description
See the original description in base::...elt
.
Usage
...elt(n)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_...elt = getFromNamespace("...elt", "backports")
foo = function(n, ...) bp_...elt(n)
foo(n = 2, "a", "b", "c")
Backport of ...length for R < 3.4.2
Description
See the original description in base::...length
.
Usage
...length()
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_...length = getFromNamespace("...length", "backports")
foo = function(...) bp_...length()
foo(1, 2, 3)
Backport of ...names for R < 4.1.0
Description
See the original description in base::...names
.
Usage
...names()
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_...names = getFromNamespace("...names", "backports")
foo = function(...) bp_...names()
foo(a = 1, b = 2, 3)
Backport of .libPaths for R < 4.1.0
Description
See the original description in base::.libPaths
.
Usage
.libPaths(new, include.site = TRUE)
Examples
save <- .libPaths()
save
# ignore the site library
.libPaths("test", include.site = FALSE)
# restore the original
.libPaths(save)
Backport of .valid.factor for R < 3.4.0
Description
See the original description in base::.valid.factor
.
Usage
.valid.factor(object)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_.valid_factor = getFromNamespace(".valid.factor", "backports")
bp_.valid_factor(factor(letters[1:3]))
Backport of R_user_dir for R < 4.0.0
Description
See the original description in tools::R_user_dir
.
Usage
R_user_dir(package, which = c("data", "config", "cache"))
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_R_user_dir = getFromNamespace("R_user_dir", "backports")
bp_R_user_dir("backports")
Backport of URLencode for R < 3.2.0
Description
See the original description in utils::URLencode
.
Argument repeated
is backported.
Usage
URLencode(URL, reserved = FALSE, repeated = FALSE)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_URLencode = getFromNamespace("URLencode", "backports")
URLdecode(z <- "ab%20cd")
c(bp_URLencode(z), bp_URLencode(z, repeated = TRUE))
Backport of anyNA for R versions < 3.2.0.
Description
See the original description in base::anyNA
.
Usage
anyNA(x, recursive = FALSE)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_anyNA = getFromNamespace("anyNA", "backports")
bp_anyNA(letters)
Backport of as.Rconcordance for R < 4.3.0
Description
See the original description in tools::as.Rconcordance
.
Usage
as.Rconcordance(x, ...)
Backport of as.Rconcordance.default for R < 4.3.0
Description
See the original description in tools::as.Rconcordance
.
Usage
## Default S3 method:
as.Rconcordance(x, ...)
Backport of as.character.Rconcordance for R < 4.3.0
Description
See the original description in tools::as.character.Rconcordance
.
Usage
## S3 method for class 'Rconcordance'
as.character(x, targetfile = "", ...)
Backport of asplit for R < 3.6.0
Description
See the original description in base::asplit
.
Usage
asplit(x, MARGIN)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_asplit = getFromNamespace("asplit", "backports")
x = matrix(1:6, 2, 3)
bp_asplit(x, 1)
Backport of capture.output for R < 3.3.0
Description
Argument type
has been backported.
See the original description in utils::capture.output
.
Usage
capture.output(
...,
file = NULL,
append = FALSE,
type = c("output", "message"),
split = FALSE
)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_capture.output <- getFromNamespace("capture.output", "backports")
captured <- bp_capture.output({ message("hi") }, type = "message")
str(captured)
Backport of dQuote and sQuote for R < 3.6.0
Description
Argument q
has been backported.
See the original description in base::dQuote()
and base::sQuote()
.
Usage
dQuote(x, q = getOption("useFancyQuotes"))
sQuote(x, q = getOption("useFancyQuotes"))
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_dQuote <- getFromNamespace("dQuote", "backports")
bp_dQuote("foo")
bp_dQuote("foo", q = TRUE)
Backport of deparse1 for R < 4.0.0
Description
See the original description in base::deparse1
.
Usage
deparse1(expr, collapse = " ", width.cutoff = 500L, ...)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_deparse1 = getFromNamespace("deparse1", "backports")
bp_deparse1(quote(`foo bar`))
Backport of dir.exists for R < 3.2.0
Description
See the original description in base::dir.exists
.
Usage
dir.exists(paths)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_dir.exists = getFromNamespace("dir.exists", "backports")
bp_dir.exists(tempdir())
Backport of endsWith for R < 3.3.0
Description
See the original description in base::endsWith
.
Usage
endsWith(x, suffix)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_endsWith = getFromNamespace("endsWith", "backports")
bp_endsWith(c("aabb", "bbcc"), "bb")
Backport of file.info
for R < 3.2.0
Description
Argument extra_cols
has been backported.
See the original description in base::file.info
.
Usage
file.info(..., extra_cols = TRUE)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_file.info = getFromNamespace("file.info", "backports")
bp_file.info(file.path(R.home(), "COPYING"), extra_cols = FALSE)
Backports of wrappers around file.info
for R < 3.2.0
Description
See the original description in base::file.size
.
Usage
file.mode(...)
file.mtime(...)
file.size(...)
Examples
# get functions from namespace instead of possibly getting
# implementations shipped with recent R versions:
bp_file.size = getFromNamespace("file.size", "backports")
bp_file.mode = getFromNamespace("file.size", "backports")
bp_file.mtime = getFromNamespace("file.size", "backports")
fn = file.path(R.home(), "COPYING")
bp_file.size(fn)
bp_file.mode(fn)
bp_file.size(fn)
Backport of get0 for R < 3.2.0
Description
See the original description in base::get0
.
Usage
get0(
x,
envir = pos.to.env(-1L),
mode = "any",
inherits = TRUE,
ifnotfound = NULL
)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_get0 = getFromNamespace("get0", "backports")
bp_get0("a")
bp_get0("a", ifnotfound = 0)
foo = 12
bp_get0("foo")
Backport of hasName for R < 3.4.0
Description
See the original description in utils::hasName
.
Usage
hasName(x, name)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_hasName = getFromNamespace("hasName", "backports")
bp_hasName(list(a = 1, b = 2), c("a", "b", "c"))
Import backported functions into your package
Description
Imports objects from backports into the namespace of other packages by assigning it during load-time. See examples for a code snippet to copy to your package.
Usage
import(pkgname, obj = NULL, force = FALSE)
Arguments
pkgname |
[ |
obj |
[ |
force |
[ |
See Also
Examples
## Not run:
# This imports all functions implemented in backports while the package is loaded
.onLoad <- function(libname, pkgname) {
backports::import(pkgname)
}
# This only imports the function "trimws"
.onLoad <- function(libname, pkgname) {
backports::import(pkgname, "trimws")
}
# This imports all backports from base and force-imports "hasName" from utils
.onLoad <- function(libname, pkgname) {
backports::import(pkgname)
backports::import(pkgname, "hasName", force = TRUE)
}
## End(Not run)
Backport of isFALSE for R < 3.4.2
Description
See the original description in base::isFALSE
.
Usage
isFALSE(x)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_isFALSE = getFromNamespace("isFALSE", "backports")
bp_isFALSE(FALSE)
bp_isFALSE(iris)
Backport of isNamespaceLoaded for R < 3.2.0
Description
See the original description in base::isNamespaceLoaded
.
Usage
isNamespaceLoaded(name)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_isNamespaceLoaded = getFromNamespace("isNamespaceLoaded", "backports")
bp_isNamespaceLoaded("backports")
Backport of isTRUE for R < 3.5.0
Description
The implementation of 'isTRUE' has been changed in R-3.5.0 from
identical(x, TRUE)
to is.logical(x) && length(x) == 1L && !is.na(x) && x
.
This backport overloads the old implementation for R versions prior to 3.5.0.
Usage
isTRUE(x)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_isTRUE = getFromNamespace("isTRUE", "backports")
bp_isTRUE(FALSE)
bp_isTRUE(iris)
Backport of lengths for R < 3.2.0
Description
See the original description in base::lengths
.
Usage
lengths(x, use.names = TRUE)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_lengths = getFromNamespace("lengths", "backports")
bp_lengths(list(1:3, 2))
Backport of list2DF for R < 4.0.0
Description
See the original description in base::list2DF
.
Note that the behaviour of list2DF()
changed in
R 4.2.0. Instead of recycling vectors to common length, an
exception is raised.
This backport implements the new behaviour,
throwing an error message.
Usage
list2DF(x = list(), nrow = 0L)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_list2DF = getFromNamespace("list2DF", "backports")
bp_list2DF(list(x = 1:3, y = 2:4))
Backport of matchConcordance for R < 4.3.0
Description
See the original description in tools::matchConcordance
.
Usage
matchConcordance(linenum, concordance)
Backport of the null-coalescing operator for R < 4.4.0
Description
See the original description in Control
.
Usage
x %||% y
Arguments
x |
(any). |
y |
(any). |
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_null_coalesce = getFromNamespace("%||%", "backports")
bp_null_coalesce(NULL, FALSE)
Backport of paste for R < 4.0.1
Description
See the original description in base::paste
.
Usage
paste(..., sep = " ", collapse = NULL, recycle0 = FALSE)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_paste = getFromNamespace("paste", "backports")
bp_paste(letters[1:3], character(), collapse = NULL, recycle0 = TRUE)
Backport of paste0 for R < 4.0.1
Description
See the original description in base::paste0
.
Usage
paste0(..., collapse = NULL, recycle0 = FALSE)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_paste0 = getFromNamespace("paste0", "backports")
bp_paste0(letters[1:3], character(), collapse = NULL, recycle0 = TRUE)
Backport of print.Rconcordance for R < 4.3.0
Description
See the original description in tools::print.Rconcordance
.
Usage
## S3 method for class 'Rconcordance'
print(x, ...)
Backport of removeSource for R < 3.6.0
Description
See the original description in utils::removeSource
.
Usage
removeSource(fn)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_removeSource = getFromNamespace("removeSource", "backports")
bp_removeSource(mean)
Backport of startsWith for R < 3.3.0
Description
See the original description in base::startsWith
.
Usage
startsWith(x, prefix)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_startsWith = getFromNamespace("startsWith", "backports")
bp_startsWith(c("aabb", "bbcc"), "bb")
Backport of stopifnot for R versions < 4.0.0.
Description
See the original description in base::stopifnot
.
Usage
stopifnot(..., exprs, exprObject, local = TRUE)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_stopifnot = getFromNamespace("stopifnot", "backports")
m <- matrix(c(1, 3, 12, 1), 2, 2)
## Not run: bp_stopifnot("m must be symmetric" = m == t(m))
Backport of str2expression for R < 3.6.0
Description
See the original description in base::str2expression
.
Usage
str2expression(text)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
str2expression <- getFromNamespace("str2expression", "backports")
str2expression("x[3] <- 1+4")
Backport of str2lang for R < 3.6.0
Description
See the original description in base::str2lang
.
Usage
str2lang(s)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
str2lang <- getFromNamespace("str2lang", "backports")
str2lang("x[3] <- 1+4")
Backport of strrep for R < 3.3.0
Description
See the original description in base::strrep
.
Usage
strrep(x, times)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_strrep = getFromNamespace("strrep", "backports")
bp_strrep("-", 10)
Backport of suppressWarnings and suppressMessages for R < 4.0.0
Description
Backport for new argument 'classes'.
See the original description in base::suppressWarnings
/base::suppressMessages
.
Usage
suppressWarnings(expr, classes = "warning")
suppressMessages(expr, classes = "message")
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_suppressWarnings = getFromNamespace("suppressWarnings", "backports")
bp_suppressWarnings(warningCondition("warning", class = "testWarning"), "testWarning")
Backport of trimws for R < 3.3.0
Description
See the original description in base::trimws
.
Usage
trimws(x, which = c("both", "left", "right"))
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_trimws = getFromNamespace("trimws", "backports")
bp_trimws(c(" a ", "b ", " c"))
bp_trimws(c(" a ", "b ", " c"), which = "left")
Backport of vignetteInfo for R < 3.6.0
Description
See the original description in tools::vignetteInfo
.
Usage
vignetteInfo(file)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_vignetteInfo = getFromNamespace("vignetteInfo", "backports")
Backport of warningCondition and errorCondition for R < 3.6.0
Description
See the original description in base::warningCondition
/base::errorCondition
.
Usage
warningCondition(msg, ..., class = NULL, call = NULL)
errorCondition(msg, ..., class = NULL, call = NULL)
Examples
# get function from namespace instead of possibly getting
# implementation shipped with recent R versions:
bp_warningCondition = getFromNamespace("warningCondition", "backports")
bp_warningCondition("package backports not found")