Dear Brodie,
on the R-devel mailing list, recently the issue was raised why
str() was printing "atomic" (instead of e.g. "int") and not
mentioning the names e.g., forkin the case
structure(1:4, .Names=letters[1:4], foo = "bar")
https://stat.ethz.ch/pipermail/r-devel/2017-November/075163.html
In previous/current versions of R, we've had
> str( structure(1:4, .Names=letters[1:4], foo = "bar") )
atomic [1:4] 1 2 3 4
- attr(*, "foo")= chr "bar"
whereas in R-devel
> str( structure(1:4, .Names=letters[1:4], foo = "bar") )
Named int [1:4] 1 2 3 4
- attr(*, "names")= chr [1:4] "a" "b" "c" "d"
- attr(*, "foo")= chr "bar"
>
which is much more internally coherent with the output (in all
versions of R) of
> str( structure(1:4, .Names=letters[1:4]) )
Named int [1:4] 1 2 3 4
- attr(*, "names")= chr [1:4] "a" "b" "c" "d"
>
..... so far for motivation.
In any case, in your testthat.misc.R ~ line 15 :
obj <- list(
a=a, b=b, c=1:50,
d=long.string,
e=list(1, structure(2, zz=list(a=1, b=list("a", ls=long.string))), e=letters)
)
str.txt <- capture.output(str(obj))
expect_equal(
diffobj:::str_levels(str.txt, wrap=FALSE),
c(0L, 1L, 3L, 1L, 2L, 4L, 1L, 1L, 1L, 2L, 2L, 3L, 4L, 4L, 5L, 5L, 2L)
)
now gives an error ... as does the subsequent test.
It is also a case where the new output is "clearly"(in the eye
of the beholder) nicer than before.
To make your check work both with "old R" (R < 3.5.0, i.e. all
versions before R-devel) and with R-devel,
you can use if(getRversion() ....) to distinguish, and indeed,
I've checked that the appended small patch makes your package
work fine with R-devel, too
Best regards,
Martin Maechler
diff -r -uBbw diffobj_CRAN/tests/testthat/testthat.misc.R diffobj/tests/testthat/testthat.misc.R
--- diffobj_CRAN/tests/testthat/testthat.misc.R 2016-11-20 15:25:34.000000000 +0100
+++ diffobj/tests/testthat/testthat.misc.R 2017-11-27 09:44:47.889579000 +0100
@@ -13,12 +13,18 @@
str.txt <- capture.output(str(obj))
expect_equal(
diffobj:::str_levels(str.txt, wrap=FALSE),
+ if(getRversion() < "3.5")
c(0L, 1L, 3L, 1L, 2L, 4L, 1L, 1L, 1L, 2L, 2L, 3L, 4L, 4L, 5L, 5L, 2L)
+ else # nicer str()
+ c(0L, 1L, 2L, 1L, 2L, 3L, 1L, 1L, 1L, 2L, 2L, 3L, 4L, 4L, 5L, 5L, 2L)
)
str.txt.w <- capture.output(str(obj, width=30L, strict.width="wrap"))
expect_equal(
diffobj:::str_levels(str.txt.w, wrap=TRUE),
+ if(getRversion() < "3.5")
c(0L, 1L, 1L, 3L, 1L, 1L, 2L, 2L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 2L, 2L)
+ else # nicer str()
+ c(0L, 1L, 2L, 1L, 1L, 2L, 2L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 2L, 2L)
)
# cat(
# paste(
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4