Skip to content

Commit 9f6db00

Browse files
restore other.Rraw tests to working state (#7560)
1 parent 3e579ee commit 9f6db00

File tree

3 files changed

+73
-10
lines changed

3 files changed

+73
-10
lines changed

inst/tests/knitr.Rmd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
```{r test_id, message=FALSE, results="show", echo=TRUE, warning=FALSE}
2+
require(data.table) # print?
3+
DT = data.table(x=1:3, y=4:6) # no
4+
DT # yes
5+
DT[, z := 7:9] # no
6+
print(DT[, z := 10:12]) # yes
7+
if (1 < 2) DT[, a := 1L] # no
8+
DT # yes
9+
```
10+
Some text.

inst/tests/knitr.md.save

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
``` r
3+
require(data.table) # print?
4+
DT = data.table(x=1:3, y=4:6) # no
5+
DT # yes
6+
```
7+
8+
```
9+
## x y
10+
## <int> <int>
11+
## 1: 1 4
12+
## 2: 2 5
13+
## 3: 3 6
14+
```
15+
16+
``` r
17+
DT[, z := 7:9] # no
18+
print(DT[, z := 10:12]) # yes
19+
```
20+
21+
```
22+
## x y z
23+
## <int> <int> <int>
24+
## 1: 1 4 10
25+
## 2: 2 5 11
26+
## 3: 3 6 12
27+
```
28+
29+
``` r
30+
if (1 < 2) DT[, a := 1L] # no
31+
DT # yes
32+
```
33+
34+
```
35+
## x y z a
36+
## <int> <int> <int> <int>
37+
## 1: 1 4 10 1
38+
## 2: 2 5 11 1
39+
## 3: 3 6 12 1
40+
```
41+
Some text.

inst/tests/other.Rraw

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ pkgs = c("DBI", "RSQLite", "bit64", "caret", "dplyr", "gdata", "ggplot2", "hexbi
1111
# "yaml" # for fread's yaml argument (csvy capability)
1212
# # zoo # In DESCRIPTION:Suggests otherwise R CMD check warning: '::' or ':::' import not declared from: 'zoo'; it is tested in other.Rraw though
1313

14-
if (exists("test.data.table",.GlobalEnv,inherits=FALSE) ||
14+
if (exists("test.data.table", .GlobalEnv, inherits=FALSE) ||
1515
!"package:data.table" %in% search()) {
16-
stop("Usage: R CMD INSTALL; require(data.table); test.data.table('other.Rraw')")
16+
stop(
17+
"Usage: R CMD INSTALL; require(data.table); test.data.table('other.Rraw')\n",
18+
" Did you try running it under cc()?"
19+
)
1720
# running other.Raw in dev mode (i.e. when data.table is not installed) is not intended to work
1821
}
1922

@@ -47,7 +50,7 @@ cat("\n")
4750
print(sessionInfo())
4851
cat("\n")
4952

50-
if (all(c("package:reshape","package:reshape2") %in% search())) {
53+
if (all(c("package:reshape", "package:reshape2") %in% search())) {
5154
warning("Packages 'reshape' and 'reshape2' are both loaded. There have been problems before when you don't use the :: namespace prefix to disambiguate. Probably best to either remove.packages('reshape') and use reshape2 instead, or always use :: when packages mask non-generic names.")
5255
}
5356

@@ -181,10 +184,14 @@ if (loaded[["knitr"]]) {
181184
# kable in knitr v1.6 uses DF[...] syntax inside it but the user might have passed a data.table.
182185
# Which is fine and works thanks to cedta().
183186
DT = data.table(x=1, y=2)
184-
test(11, kable(DT), output="x.*y.*1.*2")
185-
invisible(knit(testDir("knitr.Rmd"), quiet=TRUE))
186-
cat(readLines("knitr.md"), sep="\n")
187-
invisible(file.remove("knitr.md"))
187+
test(11.1, kable(DT), output="x.*y.*1.*2")
188+
local({
189+
old = options(datatable.print.class=TRUE)
190+
tmp = tempfile()
191+
on.exit({unlink(tmp); options(old)})
192+
invisible(knit(testDir("knitr.Rmd"), tmp, quiet=TRUE))
193+
test(11.2, tools::Rdiff(tmp, testDir("knitr.md.save")), 0L)
194+
})
188195
}
189196

190197
if (loaded[["parallel"]]) {
@@ -531,6 +538,9 @@ if (loaded[["xts"]]) { # was 1465 in tests.Rraw, #5516
531538
# was 2108 in tests.Rraw, #5516
532539
# first and last should no longer load xts namespace, #3857, below commented test for interactive validation when xts present but not loaded or attached
533540
# stopifnot("xts"%in%installed.packages(), !isNamespaceLoaded("xts")); library(data.table); x=as.POSIXct("2019-01-01"); last(x); stopifnot(!isNamespaceLoaded("xts"))
541+
# in case the search path is wrong
542+
if (!identical(last, data.table::last)) last = data.table::last
543+
if (!identical(first, data.table::first)) first = data.table::first
534544
local({
535545
x = as.POSIXct("2019-09-09")+0:1
536546
old = options(datatable.verbose=TRUE); on.exit(options(old))
@@ -686,6 +696,8 @@ if (loaded[["nanotime"]]) {
686696
# was 2080.01-05 in tests.Rraw, #5516
687697
n = nanotime(1:4)
688698
n[2L] = NA
699+
# in case the search path is wrong
700+
if (!identical(between, data.table::between)) between = data.table::between
689701
local({
690702
old = options(datatable.verbose=TRUE); on.exit(options(old))
691703
test(24.1, between(n, nanotime(2), nanotime(10)), c(FALSE, NA, TRUE, TRUE), output="between parallel processing of integer64")
@@ -779,15 +791,15 @@ if (loaded[["nanotime"]]) {
779791

780792
# tables() with large environment #6607
781793
.e <- new.env() ## to not populate the .GlobalEnv
782-
.e[["DT"]] <- as.data.table(lapply(1:15,function(i) runif(20e6)))
783-
res <- tables(env=.e)
794+
.e[["DT"]] <- setDT(replicate(15L, runif(2e7), simplify=FALSE))
795+
invisible(capture.output(res <- tables(env=.e)))
784796
test(32, res[, .(NAME,NROW,NCOL,MB)], data.table(NAME="DT",NROW=20000000L,NCOL=15L,MB=2288.0))
785797
rm(.e, res)
786798

787799
if (loaded[["vctrs"]]) {
788800
# vctrs::list_of() columns are treated the same as other list() columns
789801
DT = data.table(a = 1, b = list_of(mtcars))
790-
test(33, DT, output="<vctrs_list_of>.*<data\\.frame\\[32x11\\]>")
802+
test(33, options=c(datatable.print.class=TRUE), DT, output="<vctrs_list_of>.*<data\\.frame\\[32x11\\]>")
791803
}
792804

793805
# NB: currently, RSQLite requires DBI, so partially redundant, but future-proof.

0 commit comments

Comments
 (0)