Skip to content

Commit a7de0f8

Browse files
committed
change to frev/setrev
1 parent 276cdeb commit a7de0f8

File tree

3 files changed

+37
-40
lines changed

3 files changed

+37
-40
lines changed

R/wrappers.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,5 @@ isReallyReal = function(x) .Call(CisReallyReal, x)
1717

1818
coerceAs = function(x, as, copy=TRUE) .Call(CcoerceAs, x, as, copy)
1919

20-
frev = function(x, copy=TRUE) {
21-
ans = .Call(Cfrev, x, copy)
22-
if (isTRUE(copy)) ans else invisible(ans)
23-
}
20+
frev = function(x) .Call(Cfrev, x, TRUE)
21+
setrev = function(x) invisible(.Call(Cfrev, x, FALSE))

inst/tests/tests.Rraw

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18353,52 +18353,51 @@ if (test_bit64) {
1835318353

1835418354
# 5885 implement frev
1835518355
d = c(NA, NaN, Inf, -Inf)
18356-
test(2249.00, frev(c(FALSE, NA), copy=TRUE), c(NA, FALSE))
18357-
test(2249.01, frev(c(0L, NA), copy=TRUE), c(NA, 0L))
18358-
test(2249.02, frev(d, copy=TRUE), c(-Inf, Inf, NaN, NA))
18359-
test(2249.03, frev(c(NA, 1, 0+2i), copy=TRUE), c(0+2i, 1, NA))
18360-
test(2249.04, frev(as.raw(0:1), copy=TRUE), as.raw(1:0))
18361-
test(2249.05, frev(NULL, copy=TRUE), NULL)
18362-
test(2249.06, frev(character(5), copy=TRUE), character(5))
18363-
test(2249.07, frev(integer(0), copy=TRUE), integer(0))
18364-
test(2249.08, frev(list(1, "a"), copy=TRUE), list("a", 1))
18365-
test(2249.09, frev(c(0L, NA), copy=FALSE), c(NA, 0L))
18366-
test(2249.10, frev(d, copy=FALSE), c(-Inf, Inf, NaN, NA))
18367-
test(2249.11, frev(c(NA, 1, 0+2i), copy=FALSE), c(0+2i, 1, NA))
18368-
test(2249.12, frev(as.raw(0:1), copy=FALSE), as.raw(1:0))
18369-
test(2249.13, frev(NULL, copy=FALSE), NULL)
18370-
test(2249.14, frev(character(5), copy=FALSE), character(5))
18371-
test(2249.15, frev(integer(0), copy=FALSE), integer(0))
18372-
test(2249.16, frev(list(1, "a"), copy=FALSE), list("a", 1))
18373-
test(2249.17, frev(1:1e2, copy=TRUE), rev(1:1e2))
18356+
test(2249.00, frev(c(FALSE, NA)), c(NA, FALSE))
18357+
test(2249.01, frev(c(0L, NA)), c(NA, 0L))
18358+
test(2249.02, frev(d), c(-Inf, Inf, NaN, NA))
18359+
test(2249.03, frev(c(NA, 1, 0+2i)), c(0+2i, 1, NA))
18360+
test(2249.04, frev(as.raw(0:1)), as.raw(1:0))
18361+
test(2249.05, frev(NULL), NULL)
18362+
test(2249.06, frev(character(5)), character(5))
18363+
test(2249.07, frev(integer(0)), integer(0))
18364+
test(2249.08, frev(list(1, "a")), list("a", 1))
18365+
test(2249.09, setrev(c(0L, NA)), c(NA, 0L))
18366+
test(2249.10, setrev(d), c(-Inf, Inf, NaN, NA))
18367+
test(2249.11, setrev(c(NA, 1, 0+2i)), c(0+2i, 1, NA))
18368+
test(2249.12, setrev(as.raw(0:1)), as.raw(1:0))
18369+
test(2249.13, setrev(NULL), NULL)
18370+
test(2249.14, setrev(character(5)), character(5))
18371+
test(2249.15, setrev(integer(0)), integer(0))
18372+
test(2249.16, setrev(list(1, "a")), list("a", 1))
18373+
test(2249.17, frev(1:1e2), rev(1:1e2))
1837418374
# copy arguments
1837518375
x = 1:3
18376-
test(2249.21, {frev(x, copy=TRUE); x}, 1:3)
18377-
test(2249.22, {frev(x, copy=FALSE); x}, 3:1)
18378-
test(2249.23, address(x) == address(frev(x, copy=FALSE)))
18379-
test(2249.24, address(x) != address(frev(x, copy=TRUE)))
18376+
test(2249.21, {frev(x); x}, 1:3)
18377+
test(2249.22, {setrev(x); x}, 3:1)
18378+
test(2249.23, address(x) == address(setrev(x)))
18379+
test(2249.24, address(x) != address(frev(x)))
1838018380
# do not alter on subsets
18381-
test(2249.25, {frev(x[1:2], copy=FALSE); x}, 1:3)
18381+
test(2249.25, {setrev(x[1:2]); x}, 1:3)
1838218382
# levels
1838318383
f = as.factor(letters)
18384-
test(2249.31, frev(f, copy=TRUE), rev(f))
18385-
test(2249.32, frev(as.IDate(1:10), copy=TRUE), as.IDate(10:1))
18386-
test(2249.33, frev(as.IDate(1:10), copy=TRUE), as.IDate(10:1))
18384+
test(2249.31, frev(f), rev(f))
18385+
test(2249.32, frev(as.IDate(1:10)), as.IDate(10:1))
18386+
test(2249.33, frev(as.IDate(1:10)), as.IDate(10:1))
1838718387
# names
1838818388
x = c(a=1L, b=2L, c=3L)
18389-
test(2249.41, frev(x, copy=TRUE), rev(x))
18390-
test(2249.42, frev(x, copy=FALSE), x)
18389+
test(2249.41, frev(x), rev(x))
18390+
test(2249.42, setrev(x), x)
1839118391
# attributes
1839218392
x = structure(1:10, class = c("IDate", "Date"), att = 1L)
18393-
test(2249.51, attr(frev(x, copy=TRUE), "att"), 1L)
18394-
test(2249.52, attr(frev(x, copy=FALSE), "att"), 1L)
18393+
test(2249.51, attr(frev(x), "att"), 1L)
18394+
test(2249.52, attr(setrev(x), "att"), 1L)
1839518395
# errors
1839618396
test(2249.61, frev(data.table()), error="should not be data.frame or data.table")
18397-
test(2249.62, frev(1:2, copy=NA), error="must be TRUE or FALSE")
18398-
test(2249.63, frev(expression(1)), error="is not supported by frev")
18399-
test(2249.64, frev(matrix(1)), error="should not be matrix or array")
18397+
test(2249.62, frev(expression(1)), error="is not supported by frev")
18398+
test(2249.63, frev(matrix(1)), error="should not be matrix or array")
1840018399
if (test_bit64) {
1840118400
x = as.integer64(c(1, NA, 3))
18402-
test(2249.71, frev(x, copy=TRUE), rev(x))
18403-
test(2249.72, frev(x, copy=FALSE), x)
18401+
test(2249.71, frev(x), rev(x))
18402+
test(2249.72, setrev(x), x)
1840418403
}

src/utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ SEXP frev(SEXP x, SEXP copyArg) {
430430
if (!isNull(getAttrib(x, R_DimSymbol)))
431431
error(_("'x' should not be matrix or array"));
432432
if (!IS_TRUE_OR_FALSE(copyArg))
433-
error(_("%s must be TRUE or FALSE."), "copy");
433+
error(_("%s must be TRUE or FALSE."), "copy"); // # nocov
434434
bool copy = LOGICAL(copyArg)[0];
435435
R_xlen_t n = xlength(x);
436436
int nprotect = 0;

0 commit comments

Comments
 (0)