Skip to content

Commit

Permalink
Fix other.Rraw tests to run locally (#6097)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Apr 22, 2024
1 parent d420afe commit 20126b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
15 changes: 9 additions & 6 deletions inst/tests/other.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ f = function(pkg) suppressWarnings(suppressMessages(isTRUE(
)))
loaded = sapply(pkgs, f)
if (any(!loaded)) {
stop("test.data.table('other.Rraw') is missing required package(s): ", paste(names(loaded)[!loaded], collapse=", "), ". If you can't install them and this is R CMD check, please set environment variable TEST_DATA_TABLE_WITH_OTHER_PACKAGES back to the default, false.")
stop("test.data.table('other.Rraw') is missing required package(s): ", toString(names(loaded)[!loaded]), ". If you can't install them and this is R CMD check, please set environment variable TEST_DATA_TABLE_WITH_OTHER_PACKAGES back to the default, false.")
# Would like to install them now for convenience but gitlab-ci.yml seems to install to bus/mirror-other-packages/cran.
# If that's a cache, that's nice, but we don't know at this point whether this script is being run by GLCI or by a user or in dev.
# We don't allow skipping (e.g. if _R_CHECK_FORCE_SUGGESTS_ is FALSE) to keep things simple and to keep things strict; i.e.
# if this script runs then we want to be sure it has fully passed.
}

cat("\n")
print(data.table(pkg=pkgs, loaded)[loaded==TRUE, version:=as.character(sapply(pkg, function(p) format(packageVersion(p))))][])
print(data.table(pkg=pkgs, loaded)[loaded==TRUE, .(pkg, version=sapply(pkg, function(p) format(packageVersion(p))))])
cat("\n")
print(sessionInfo())
cat("\n")
Expand All @@ -50,7 +50,9 @@ if (loaded[["ggplot2"]]) {
test(1.2, DT[,print(ggplot(.SD,aes(b,f))+geom_point()),by=list(grp%%2L)],data.table(grp=integer())) # %%2 to reduce time needed for ggplot2 to plot
if (loaded[["hexbin"]]) {
# Test reported by C Neff on 11 Oct 2011
test(1.3, names(print(ggplot(DT) + geom_hex(aes(b, f)) + facet_wrap(~grp)))[c(1,3)], c("data","scales"))
# TODO(r-lib/gtable#94): don't suppressWarnings() here.
x <- suppressWarnings(print(ggplot(DT) + geom_hex(aes(b, f)) + facet_wrap(~grp)))
test(1.3, names(x)[c(1L, 3L)], c("data", "scales"))
}
# Test plotting ITime with ggplot2 which seems to require an as.data.frame method for ITime, #1713
datetimes = c("2011 NOV18 09:29:16", "2011 NOV18 10:42:40", "2011 NOV18 23:47:12",
Expand Down Expand Up @@ -97,7 +99,8 @@ if (loaded[["caret"]]) {
# So I put the win-builder fail down to resource issues and moved this test into test.data.table("other.Rraw").
DT = data.table(x = rnorm(10), y = rnorm(10))
cv.ctrl = trainControl(method = 'repeatedcv', number = 5, repeats = 1)
fit = train(y ~ x, data = DT, 'lm', trControl = cv.ctrl)
# TODO(topepo/caret#1361): remove suppressWarnings() for partially matched args internal to caret
fit = suppressWarnings(train(y ~ x, data = DT, 'lm', trControl = cv.ctrl))
test(4, names(DT), c("x", "y"))
}

Expand Down Expand Up @@ -209,7 +212,7 @@ test(14.1, {example(':=', package='data.table', local=TRUE, echo=FALSE); TRUE})
test(14.2, {example('CJ', package='data.table', local=TRUE, echo=FALSE); TRUE})

if (loaded[["sf"]]) { #2273
DT = as.data.table(st_read(system.file("shape/nc.shp", package = "sf")))
DT = as.data.table(st_read(system.file("shape/nc.shp", package = "sf"), quiet=TRUE))
test(15, DT[1:3, .(NAME, FIPS, geometry)], output="Ashe.*-81.4.*Surry.*-80.4")

dsf = sf::st_as_sf(data.table(x=1:10, y=1:10, s=sample(1:2, 10, TRUE)), coords=1:2)
Expand Down Expand Up @@ -724,6 +727,6 @@ if (FALSE) { # moved from tests.Rraw in #5517 and not yet back on; wasn't sure

if (loaded[["dplyr"]]) {
# regression test for converting character->list column in a magrittr (dplyr) pipe, #2651
DT = data.table(a = 1, b = 2, c = '1,2,3,4]', d = 4)
DT = data.table(a = 1, b = 2, c = '1,2,3,4', d = 4)
test(30, DT[, c := strsplit(c, ',', fixed = TRUE) %>% lapply(as.integer) %>% as.list]$c, list(1:4))
}
12 changes: 2 additions & 10 deletions tests/other.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
require(data.table)
library(data.table)
if (!as.logical(Sys.getenv("TEST_DATA_TABLE_WITH_OTHER_PACKAGES", "FALSE"))) {
cat("Skipping tests in 'other' and quitting, set TEST_DATA_TABLE_WITH_OTHER_PACKAGES to proceed.\n")
q('no')
}

options(warn=1)
# test.data.table() turns on R's warnPartial* options and currently there
# are partial argument names used in base and other packages. Without the
# options(warn=1), other.Rout just contains "There were 16 warnings (use
# warnings() to see them)". However, a print(warnings()) after test.data.table()
# just results in NULL in other.Rout. Hence options(warn=1) because that
# worked to display the warnings, not because we want them displayed at the
# time per se.

test.data.table(script="other.Rraw")

0 comments on commit 20126b1

Please sign in to comment.