[med-svn] [r-cran-backports] 09/12: New upstream version 1.1.1
Andreas Tille
tille at debian.org
Thu Sep 28 15:47:24 UTC 2017
This is an automated email from the git hooks/post-receive script.
tille pushed a commit to branch master
in repository r-cran-backports.
commit 2ff523f9cb34a9d8193ada5d21ac67c4611f801e
Author: Andreas Tille <tille at debian.org>
Date: Thu Sep 28 19:45:09 2017 +0200
New upstream version 1.1.1
---
DESCRIPTION | 10 +++++-----
MD5 | 50 +++++++++++++++++++++++++++++++------------------
NAMESPACE | 8 +++++++-
NEWS.md | 18 +++++++++++++++---
R/dotsElt.R | 19 +++++++++++++++++++
R/dotsLength.R | 19 +++++++++++++++++++
R/import.R | 50 +++++++++++++++++++++++++++++++++++++++++++++++++
R/isFALSE.R | 18 ++++++++++++++++++
R/lengths.R | 2 +-
R/trimws.R | 11 ++++++-----
R/zzz.R | 4 ++++
man/anyNA.Rd | 1 -
man/dir.exists.Rd | 1 -
man/dotsElt.Rd | 20 ++++++++++++++++++++
man/dotsLength.Rd | 20 ++++++++++++++++++++
man/endsWith.Rd | 1 -
man/file.info.Rd | 1 -
man/file.size.Rd | 1 -
man/get0.Rd | 1 -
man/hasName.Rd | 1 -
man/import.Rd | 37 ++++++++++++++++++++++++++++++++++++
man/isFALSE.Rd | 20 ++++++++++++++++++++
man/lengths.Rd | 1 -
man/startsWith.Rd | 1 -
man/strrep.Rd | 1 -
man/trimws.Rd | 1 -
src/dotsElt.c | 18 ++++++++++++++++++
src/dotsLength.c | 9 +++++++++
src/init.c | 19 +++++++++++++++++++
tests/helper/helper.R | 8 ++++++++
tests/test_dotsElt.R | 19 +++++++++++++++++++
tests/test_dotsLength.R | 22 ++++++++++++++++++++++
tests/test_isFALSE.R | 8 ++++++++
33 files changed, 376 insertions(+), 44 deletions(-)
diff --git a/DESCRIPTION b/DESCRIPTION
index b2b2bb7..c67cdb4 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,7 +1,7 @@
Package: backports
Type: Package
Title: Reimplementations of Functions Introduced Since R-3.0.0
-Version: 1.0.5
+Version: 1.1.1
Author: Michel Lang <michellang at gmail.com>
Maintainer: Michel Lang <michellang at gmail.com>
Description: Implementations of functions which have been introduced in
@@ -13,11 +13,11 @@ Description: Implementations of functions which have been introduced in
URL: https://github.com/mllg/backports
BugReports: https://github.com/mllg/backports/issues
License: GPL-2
-NeedsCompilation: no
+NeedsCompilation: yes
ByteCompile: yes
Depends: R (>= 3.0.0)
Imports: utils
-RoxygenNote: 5.0.1
-Packaged: 2017-01-18 08:47:45 UTC; lang
+RoxygenNote: 6.0.1
+Packaged: 2017-09-25 20:20:29 UTC; michel
Repository: CRAN
-Date/Publication: 2017-01-18 18:07:29
+Date/Publication: 2017-09-25 22:09:46 UTC
diff --git a/MD5 b/MD5
index 95ec011..c56360f 100644
--- a/MD5
+++ b/MD5
@@ -1,8 +1,10 @@
-32d1d445f09bb092d53ef99d3bbf8e44 *DESCRIPTION
-ab1d7fcd59d3ddd9ea3743fecdc17146 *NAMESPACE
-d59425cdec7efac9488b6bcc223352a1 *NEWS.md
+7d9a173e3adbd7615209e2744c767ead *DESCRIPTION
+9524e543ce2757aa366531491adc46a8 *NAMESPACE
+94fd66585d28825ed4a8ba839d9bb13b *NEWS.md
41879b295859b9f3dd0efc69737d4a12 *R/anyNA.R
e1fb60c17ea8a6677c3a80637f88c830 *R/dir.exists.R
+da64e21c278b5017993dcc2321552c8f *R/dotsElt.R
+481b7311ab8961c4fef48b8ec6cd5eb0 *R/dotsLength.R
8d6708837ab0c9222d582576160dcdeb *R/endsWith.R
daf73a06568906502efabcfa63cc3f45 *R/file.info.R
f03ad94562dfb233f213366ceb192900 *R/file.mode.R
@@ -10,31 +12,43 @@ f03ad94562dfb233f213366ceb192900 *R/file.mode.R
fd795349608133c5b9b4850c8bce7115 *R/file.size.R
14e2f4982a54c0309a4fa7ca4309c286 *R/get0.R
b8bd9db45b49fe62e5101de2d80ac4ef *R/hasName.R
-1c40ec181e9e985ecd5d779c8f0e0395 *R/lengths.R
+62cd751df30011956bbb8e0e9c97c58d *R/import.R
+71f82c7d4d76ea1bcf50c4882f2922a0 *R/isFALSE.R
+ee095da4109d7e289d11248e13ac9428 *R/lengths.R
1d59834fa8a4c2572b8a047376837618 *R/startsWith.R
a4f40e3e2747b16bfe0cc6e80766e0f7 *R/strrep.R
-16341e541b227fbea9ec39503aee1181 *R/trimws.R
-78381589fed1c969ffe6c29970c4f2a0 *R/zzz.R
-bcc319894b0b1d5b341cd19c6552d0bc *man/anyNA.Rd
-908494c399056711f8df5003109b66b9 *man/dir.exists.Rd
-2942707dce880344eee9f730ae3c80d8 *man/endsWith.Rd
-e127ecfea33a757e681ba337e9c34103 *man/file.info.Rd
-ba75af7eaebfb1aad2e8a1866a7d7541 *man/file.size.Rd
-cd6eb792757e179bdb1a2d107c1b223a *man/get0.Rd
-d5dcfc16f981142e262427e8b13d95b1 *man/hasName.Rd
-4acd0d857fe0f05100e786c0b2f89e00 *man/lengths.Rd
-c0f25ff641325cf872c8bfa29e7d0837 *man/startsWith.Rd
-3c2dae33d42ba1fa42aacb482887597b *man/strrep.Rd
-f21fa9bd13531a4865910ae41a576179 *man/trimws.Rd
-f941990fd3a8aae0d97cfb6de2a62871 *tests/helper/helper.R
+2281b9271b328f1ce44735f433c57a1b *R/trimws.R
+b6bb3ebe20a41ed2dedea35f4809081e *R/zzz.R
+5c3ef8d8d05cd9f2b6d63210b5924faa *man/anyNA.Rd
+a96f841e5bb26d875daafdec0ca3a12e *man/dir.exists.Rd
+4b811bda283420d6bda01b250112119b *man/dotsElt.Rd
+54f762138570780eaacbd437e19c6ff4 *man/dotsLength.Rd
+fff4aab715b29f9a293e46eedbba73fc *man/endsWith.Rd
+4ad72c0183de86f7435b66fdd617dbf2 *man/file.info.Rd
+f0364a969e7687778d4b2e2a651612a0 *man/file.size.Rd
+d3cbd22979c771d5d8458b741f850439 *man/get0.Rd
+f6d4b60d090845baa1d66917e6c649ae *man/hasName.Rd
+790787c2b04b8ee3674206e03db38412 *man/import.Rd
+0ef694f3021e07f821b76875888c6702 *man/isFALSE.Rd
+3193f8a1b410c99da87cdfd2306e4741 *man/lengths.Rd
+0a5e953c05afce33ff2f200ce43cb536 *man/startsWith.Rd
+71dccde721e5e07b058ea9988d2aa758 *man/strrep.Rd
+44c533774b88159cbd550b9d842d65a2 *man/trimws.Rd
+d59274bb19ef27e3774e9d1bed9fb93e *src/dotsElt.c
+dea82a2ee366ce1253864931672df2cd *src/dotsLength.c
+c068b1377f387aa3ba2ab026af9cb94d *src/init.c
+6004fbeeebd766931659360c64fd238c *tests/helper/helper.R
1b97afed1a49ba2f7e7588661dd78481 *tests/test_anyNA.R
d012f4fc8d451334726a1609bb6d0584 *tests/test_dir.exists.R
+ff243305cbfd7c6c20dcf75a8b2f9b2c *tests/test_dotsElt.R
+18ccf5227a80053f5b65dea32dff8562 *tests/test_dotsLength.R
d20ca8e00de706dfca77fc4e7e079a30 *tests/test_file.info.R
8863972af374c21d56ea2625f357d1c1 *tests/test_file.mode.R
80309a60390999f8c875299d5343311a *tests/test_file.mtime.R
608d8ef6d47fde8c311efeb92600e7c5 *tests/test_file.size.R
8bbb0281ed2c45c26a8b1fe8829a8426 *tests/test_get0.R
224c4b67349277afb9ab178127d03470 *tests/test_hasName.R
+59979fcc9294d65ac56ec1f5af289421 *tests/test_isFALSE.R
01ea7785d2d97d7364427f69ee028e43 *tests/test_lengths.R
f5a7d4c6f5a89cd18a06029135ad1e57 *tests/test_startsWith.R
f7bb3f7fe9fcfd990f6090c5fce29870 *tests/test_strrep.R
diff --git a/NAMESPACE b/NAMESPACE
index d283b1a..535fc5d 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand
+export(import)
if (getRversion() < "3.2.0") export(anyNA)
if (getRversion() < "3.2.0") export(dir.exists)
if (getRversion() < "3.2.0") export(file.info)
@@ -7,10 +8,15 @@ if (getRversion() < "3.2.0") export(file.mode)
if (getRversion() < "3.2.0") export(file.mtime)
if (getRversion() < "3.2.0") export(file.size)
if (getRversion() < "3.2.0") export(get0)
+if (getRversion() < "3.2.0") export(lengths)
if (getRversion() < "3.2.0") export(trimws)
if (getRversion() < "3.3.0") export(endsWith)
-if (getRversion() < "3.3.0") export(lengths)
if (getRversion() < "3.3.0") export(startsWith)
if (getRversion() < "3.3.0") export(strrep)
if (getRversion() < "3.4.0") export(hasName)
+if (getRversion() < "3.5.0") export(...elt)
+if (getRversion() < "3.5.0") export(...length)
+if (getRversion() < "3.5.0") export(isFALSE)
importFrom(utils,getFromNamespace)
+useDynLib(backports,dotsElt)
+useDynLib(backports,dotsLength)
diff --git a/NEWS.md b/NEWS.md
index a1885da..4bb6b60 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,15 @@
+# backports 1.1.1
+
+* Added `...length()` and `...elt()` for R versions prior to 3.5.0.
+* Added `isFALSE()` for R versions prior to 3.5.0.
+
+# backports 1.1.0
+
+* New import mechanism to import packages during load-time with the function `import()`.
+ This is now the recommended way to use backports non-interactively.
+ Simply importing backports in the NAMESPACE still works, but is comparably error-prone
+ if the same library is used by multiple R installations.
+
# backports 1.0.5
* Added `get0()` for R versions prior to 3.2.0.
@@ -5,12 +17,12 @@
# backports 1.0.4
-* Added `hasName()` for R versions prior to 3.4.0
+* Added `hasName()` for R versions prior to 3.4.0.
* Added `file.info()` with backport for argument `extra_cols`.
# backports 1.0.3
-* Removed stringi dependency
+* Removed stringi dependency.
# backports 1.0.2
@@ -18,7 +30,7 @@
# backports 1.0.1
-* Added `file.size()`, `file.mtime()` and `file.mode()` for R versions prior to 3.2.0
+* Added `file.size()`, `file.mtime()` and `file.mode()` for R versions prior to 3.2.0.
# backports 1.0.0
diff --git a/R/dotsElt.R b/R/dotsElt.R
new file mode 100644
index 0000000..32f2647
--- /dev/null
+++ b/R/dotsElt.R
@@ -0,0 +1,19 @@
+#' @title Backport of ...elt for R < 3.4.2
+#' @rdname dotsElt
+#'
+#' @description
+#' See the original description in \code{base::...elt}.
+#'
+#' @keywords internal
+#' @rawNamespace if (getRversion() < "3.5.0") export(...elt)
+#' @useDynLib backports dotsElt
+#' @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")
+...elt = function(n) {
+ .Call(dotsElt, parent.frame(), as.integer(n))
+}
diff --git a/R/dotsLength.R b/R/dotsLength.R
new file mode 100644
index 0000000..db726c2
--- /dev/null
+++ b/R/dotsLength.R
@@ -0,0 +1,19 @@
+#' @title Backport of ...length for R < 3.4.2
+#' @rdname dotsLength
+#'
+#' @description
+#' See the original description in \code{base::...length}.
+#'
+#' @keywords internal
+#' @rawNamespace if (getRversion() < "3.5.0") export(...length)
+#' @useDynLib backports dotsLength
+#' @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)
+...length = function() {
+ .Call(dotsLength, parent.frame())
+}
diff --git a/R/import.R b/R/import.R
new file mode 100644
index 0000000..f3fec87
--- /dev/null
+++ b/R/import.R
@@ -0,0 +1,50 @@
+#' @title Import backported functions into your package
+#'
+#' @description
+#' Imports objects from \pkg{backports} into the namespace of other packages
+#' by assigning it during load-time.
+#' See examples for a code snippet to copy to your package.
+#'
+#' @param pkgname [\code{character(1)}]\cr
+#' Name of the package where the backported function should be assigned.
+#' @param obj [\code{character}]\cr
+#' Name of objects to assign, as character vector.
+#' If \code{NULL}, all backports which are not provided by R itself are assigned.
+#' @export
+#' @seealso \code{\link[base]{.onLoad}}
+#' @examples
+#' \dontrun{
+#' # 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")
+#' }
+#' }
+import = function(pkgname, obj = NULL) {
+ if (getRversion() < "3.5.0") {
+ pkg = getNamespace(pkgname)
+ backports = getNamespace("backports")
+
+ assignIfNotExists = function(x, where) {
+ if (!exists(x, envir = where))
+ assign(x, get(x, envir = backports), envir = pkg)
+ }
+
+ if (!is.null(obj)) {
+ BASE = intersect(BASE, obj)
+ UTILS = intersect(UTILS, obj)
+ }
+
+ lapply(BASE, assignIfNotExists, where = baseenv())
+ lapply(UTILS, assignIfNotExists, where = getNamespace("utils"))
+ }
+ invisible(TRUE)
+}
+
+# constants used in import()
+BASE = c("anyNA", "dir.exists", "endsWith", "file.info", "file.mode", "file.mtime", "file.size", "get0", "lengths", "startsWith", "strrep", "trimws", "...length", "...elt", "isFALSE")
+UTILS = "hasName"
diff --git a/R/isFALSE.R b/R/isFALSE.R
new file mode 100644
index 0000000..0a60f24
--- /dev/null
+++ b/R/isFALSE.R
@@ -0,0 +1,18 @@
+#' @title Backport of isFALSE for R < 3.4.2
+#' @rdname isFALSE
+#'
+#' @description
+#' See the original description in \code{base::isFALSE}.
+#'
+#' @keywords internal
+#' @rawNamespace if (getRversion() < "3.5.0") export(isFALSE)
+#' @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)
+isFALSE = function(x) {
+ is.logical(x) && length(x) == 1L && !is.na(x) && !x
+}
diff --git a/R/lengths.R b/R/lengths.R
index 6612633..92597d9 100644
--- a/R/lengths.R
+++ b/R/lengths.R
@@ -5,7 +5,7 @@
#' See the original description in \code{base::lengths}.
#'
#' @keywords internal
-#' @rawNamespace if (getRversion() < "3.3.0") export(lengths)
+#' @rawNamespace if (getRversion() < "3.2.0") export(lengths)
#' @examples
#' # get function from namespace instead of possibly getting
#' # implementation shipped with recent R versions:
diff --git a/R/trimws.R b/R/trimws.R
index a059871..45380a7 100644
--- a/R/trimws.R
+++ b/R/trimws.R
@@ -15,9 +15,10 @@
#' bp_trimws(c(" a ", "b ", " c"), which = "left")
trimws = function(x, which = c("both", "left", "right")) {
which = match.arg(which)
- if (which %in% c("left", "both"))
- x = gsub("^[[:space:]]", "", x)
- if (which %in% c("right", "both"))
- x = gsub("[[:space:]]$", "", x)
- return(x)
+ mysub = function(re, x) sub(re, "", x, perl = TRUE)
+ if (which == "left")
+ return(mysub("^[ \t\r\n]+", x))
+ if (which == "right")
+ return(mysub("[ \t\r\n]+$", x))
+ mysub("[ \t\r\n]+$", mysub("^[ \t\r\n]+", x))
}
diff --git a/R/zzz.R b/R/zzz.R
index 1841b12..9f5c740 100644
--- a/R/zzz.R
+++ b/R/zzz.R
@@ -1,2 +1,6 @@
#' @importFrom utils getFromNamespace
NULL
+
+.onUnload = function (libpath) {
+ library.dynam.unload("backports", libpath)
+}
diff --git a/man/anyNA.Rd b/man/anyNA.Rd
index a7ca36d..93972dc 100644
--- a/man/anyNA.Rd
+++ b/man/anyNA.Rd
@@ -17,4 +17,3 @@ bp_anyNA = getFromNamespace("anyNA", "backports")
bp_anyNA(letters)
}
\keyword{internal}
-
diff --git a/man/dir.exists.Rd b/man/dir.exists.Rd
index e341220..e906d61 100644
--- a/man/dir.exists.Rd
+++ b/man/dir.exists.Rd
@@ -17,4 +17,3 @@ bp_dir.exists = getFromNamespace("dir.exists", "backports")
bp_dir.exists(tempdir())
}
\keyword{internal}
-
diff --git a/man/dotsElt.Rd b/man/dotsElt.Rd
new file mode 100644
index 0000000..2f2d2c0
--- /dev/null
+++ b/man/dotsElt.Rd
@@ -0,0 +1,20 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/dotsElt.R
+\name{...elt}
+\alias{...elt}
+\title{Backport of ...elt for R < 3.4.2}
+\usage{
+...elt(n)
+}
+\description{
+See the original description in \code{base::...elt}.
+}
+\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")
+}
+\keyword{internal}
diff --git a/man/dotsLength.Rd b/man/dotsLength.Rd
new file mode 100644
index 0000000..ea291f4
--- /dev/null
+++ b/man/dotsLength.Rd
@@ -0,0 +1,20 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/dotsLength.R
+\name{...length}
+\alias{...length}
+\title{Backport of ...length for R < 3.4.2}
+\usage{
+...length()
+}
+\description{
+See the original description in \code{base::...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)
+}
+\keyword{internal}
diff --git a/man/endsWith.Rd b/man/endsWith.Rd
index a914e0b..14ab127 100644
--- a/man/endsWith.Rd
+++ b/man/endsWith.Rd
@@ -17,4 +17,3 @@ bp_endsWith = getFromNamespace("endsWith", "backports")
bp_endsWith(c("aabb", "bbcc"), "bb")
}
\keyword{internal}
-
diff --git a/man/file.info.Rd b/man/file.info.Rd
index 375b406..40ccc99 100644
--- a/man/file.info.Rd
+++ b/man/file.info.Rd
@@ -18,4 +18,3 @@ bp_file.info = getFromNamespace("file.info", "backports")
bp_file.info(file.path(R.home(), "COPYING"), extra_cols = FALSE)
}
\keyword{internal}
-
diff --git a/man/file.size.Rd b/man/file.size.Rd
index 88acfec..0a59143 100644
--- a/man/file.size.Rd
+++ b/man/file.size.Rd
@@ -28,4 +28,3 @@ bp_file.mode(fn)
bp_file.size(fn)
}
\keyword{internal}
-
diff --git a/man/get0.Rd b/man/get0.Rd
index 4d88fca..e68fc2d 100644
--- a/man/get0.Rd
+++ b/man/get0.Rd
@@ -22,4 +22,3 @@ foo = 12
bp_get0("foo")
}
\keyword{internal}
-
diff --git a/man/hasName.Rd b/man/hasName.Rd
index 6b01dbf..89bb4cb 100644
--- a/man/hasName.Rd
+++ b/man/hasName.Rd
@@ -17,4 +17,3 @@ bp_hasName = getFromNamespace("hasName", "backports")
bp_hasName(list(a = 1, b = 2), c("a", "b", "c"))
}
\keyword{internal}
-
diff --git a/man/import.Rd b/man/import.Rd
new file mode 100644
index 0000000..c91d395
--- /dev/null
+++ b/man/import.Rd
@@ -0,0 +1,37 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/import.R
+\name{import}
+\alias{import}
+\title{Import backported functions into your package}
+\usage{
+import(pkgname, obj = NULL)
+}
+\arguments{
+\item{pkgname}{[\code{character(1)}]\cr
+Name of the package where the backported function should be assigned.}
+
+\item{obj}{[\code{character}]\cr
+Name of objects to assign, as character vector.
+If \code{NULL}, all backports which are not provided by R itself are assigned.}
+}
+\description{
+Imports objects from \pkg{backports} into the namespace of other packages
+by assigning it during load-time.
+See examples for a code snippet to copy to your package.
+}
+\examples{
+\dontrun{
+# 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")
+}
+}
+}
+\seealso{
+\code{\link[base]{.onLoad}}
+}
diff --git a/man/isFALSE.Rd b/man/isFALSE.Rd
new file mode 100644
index 0000000..ebc5022
--- /dev/null
+++ b/man/isFALSE.Rd
@@ -0,0 +1,20 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/isFALSE.R
+\name{isFALSE}
+\alias{isFALSE}
+\title{Backport of isFALSE for R < 3.4.2}
+\usage{
+isFALSE(x)
+}
+\description{
+See the original description in \code{base::isFALSE}.
+}
+\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)
+}
+\keyword{internal}
diff --git a/man/lengths.Rd b/man/lengths.Rd
index 16193ed..6a208fc 100644
--- a/man/lengths.Rd
+++ b/man/lengths.Rd
@@ -17,4 +17,3 @@ bp_lengths = getFromNamespace("lengths", "backports")
bp_lengths(list(1:3, 2))
}
\keyword{internal}
-
diff --git a/man/startsWith.Rd b/man/startsWith.Rd
index d252cd3..73094df 100644
--- a/man/startsWith.Rd
+++ b/man/startsWith.Rd
@@ -17,4 +17,3 @@ bp_startsWith = getFromNamespace("startsWith", "backports")
bp_startsWith(c("aabb", "bbcc"), "bb")
}
\keyword{internal}
-
diff --git a/man/strrep.Rd b/man/strrep.Rd
index 4ee5c31..6bc4b35 100644
--- a/man/strrep.Rd
+++ b/man/strrep.Rd
@@ -17,4 +17,3 @@ bp_strrep = getFromNamespace("strrep", "backports")
bp_strrep("-", 10)
}
\keyword{internal}
-
diff --git a/man/trimws.Rd b/man/trimws.Rd
index 0dc2178..ed38653 100644
--- a/man/trimws.Rd
+++ b/man/trimws.Rd
@@ -18,4 +18,3 @@ bp_trimws(c(" a ", "b ", " c"))
bp_trimws(c(" a ", "b ", " c"), which = "left")
}
\keyword{internal}
-
diff --git a/src/dotsElt.c b/src/dotsElt.c
new file mode 100644
index 0000000..2678355
--- /dev/null
+++ b/src/dotsElt.c
@@ -0,0 +1,18 @@
+#include <R.h>
+#include <Rinternals.h>
+
+SEXP dotsElt(SEXP env_, SEXP i_) {
+ SEXP ddd = findVar(R_DotsSymbol, env_);
+ int i = INTEGER(i_)[0];
+ R_len_t n = length(ddd);
+
+ if (ddd == R_UnboundValue)
+ error("incorrect context: the current call has no '...' to look in");
+ if (i <= 0)
+ error("indexing '...' with non-positive index %d", i);
+ if (i > n)
+ error("the ... list does not contain %d elements", i);
+
+ ddd = nthcdr(ddd, i - 1);
+ return eval(CAR(ddd), env_);
+}
diff --git a/src/dotsLength.c b/src/dotsLength.c
new file mode 100644
index 0000000..1141cc1
--- /dev/null
+++ b/src/dotsLength.c
@@ -0,0 +1,9 @@
+#include <R.h>
+#include <Rinternals.h>
+
+SEXP dotsLength(SEXP env_) {
+ SEXP ddd = findVar(R_DotsSymbol, env_);
+ if (ddd == R_UnboundValue)
+ error("incorrect context: the current call has no '...' to look in");
+ return ScalarInteger(TYPEOF(ddd) == DOTSXP ? length(ddd) : 0);
+}
diff --git a/src/init.c b/src/init.c
new file mode 100644
index 0000000..5107ba2
--- /dev/null
+++ b/src/init.c
@@ -0,0 +1,19 @@
+#include <R.h>
+#include <Rinternals.h>
+#include <stdlib.h> // for NULL
+#include <R_ext/Rdynload.h>
+
+/* .Call calls */
+extern SEXP dotsElt(SEXP, SEXP);
+extern SEXP dotsLength(SEXP);
+
+static const R_CallMethodDef CallEntries[] = {
+ {"dotsElt", (DL_FUNC) &dotsElt, 2},
+ {"dotsLength", (DL_FUNC) &dotsLength, 1},
+ {NULL, NULL, 0}
+};
+
+void R_init_backports(DllInfo *dll) {
+ R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
+ R_useDynamicSymbols(dll, FALSE);
+}
diff --git a/tests/helper/helper.R b/tests/helper/helper.R
index 442b33b..34cc571 100644
--- a/tests/helper/helper.R
+++ b/tests/helper/helper.R
@@ -8,6 +8,14 @@ expect_true = function(x) {
stopifnot(isTRUE(x))
}
+expect_error = function(x, pattern = NULL) {
+ ok = try(eval.parent(substitute(x)), silent = TRUE)
+ if (!inherits(ok, "try-error"))
+ stop(deparse(substitute(x)), " did not throw an error")
+ if (!is.null(pattern) && !grepl(pattern, as.character(ok)))
+ stop(sprintf("Expected error message matching '%s', got '%s'", pattern, backports:::trimws(as.character(ok))))
+}
+
makeCompareFun = function(f1, f2, ...) {
f1 = match.fun(f1)
f2 = match.fun(f2)
diff --git a/tests/test_dotsElt.R b/tests/test_dotsElt.R
new file mode 100644
index 0000000..24c7114
--- /dev/null
+++ b/tests/test_dotsElt.R
@@ -0,0 +1,19 @@
+source("helper/helper.R")
+
+wb = function(n, ...) backports:::...elt(n)
+
+if (exists("...elt", envir = baseenv())) {
+ f = get("...elt", envir = baseenv())
+ wf = function(n, ...) f(n)
+ expect_same = makeCompareFun(wf, wb)
+
+ expect_same(1, 1, 2, 3)
+ expect_same(2, 1, 2, 3)
+ expect_same(3, 1, 2, 3)
+}
+
+expect_identical(wb(1, "a", "b", "c"), "a")
+expect_identical(wb(2, "a", "b", "c"), "b")
+expect_identical(wb(3, "a", "b", "c"), "c")
+expect_error(wb(0, "a"), "non-positive")
+expect_error(wb(2, "a"), "does not contain")
diff --git a/tests/test_dotsLength.R b/tests/test_dotsLength.R
new file mode 100644
index 0000000..6a8006e
--- /dev/null
+++ b/tests/test_dotsLength.R
@@ -0,0 +1,22 @@
+source("helper/helper.R")
+
+wb = function(...) backports:::...length()
+
+if (exists("...length", envir = baseenv())) {
+ f = get("...length", envir = baseenv())
+ wf = function(...) f()
+ expect_same = makeCompareFun(wf, wb)
+
+ expect_same(1)
+ expect_same(1, 2)
+ expect_same()
+}
+
+expect_identical(wb(1, "a", "b", "c"), 4L)
+expect_identical(wb(2, "a", "b"), 3L)
+expect_identical(wb(1), 1L)
+expect_identical(wb(), 0L)
+
+f = function(n) backports:::...length()
+expect_error(f(), "current call")
+expect_error(f(1), "current call")
diff --git a/tests/test_isFALSE.R b/tests/test_isFALSE.R
new file mode 100644
index 0000000..a358bf0
--- /dev/null
+++ b/tests/test_isFALSE.R
@@ -0,0 +1,8 @@
+source("helper/helper.R")
+
+
+f = backports:::isFALSE
+expect_identical(f(FALSE), TRUE)
+expect_identical(f(TRUE), FALSE)
+expect_identical(f(1), FALSE)
+expect_identical(f(iris), FALSE)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/r-cran-backports.git
More information about the debian-med-commit
mailing list