diff --git a/R/highlevel64.R b/R/highlevel64.R index 876be20..b0eb58b 100644 --- a/R/highlevel64.R +++ b/R/highlevel64.R @@ -2022,20 +2022,6 @@ unipos.integer64 <- function(x #' #' message("via as.integer64.factor we can use 'table.integer64' also for factors") #' table.integer64(x, as.integer64(as.factor(z))) -#' -#' \dontshow{ -#' stopifnot(identical(table.integer64(as.integer64(c(1,1,2))), table(c(1,1,2)))) -#' stopifnot(identical(table.integer64(as.integer64(c(1,1,2)),as.integer64(c(3,4,4))), table(c(1,1,2),c(3,4,4)))) -#' message("the following works with three warnings due to coercion") -#' stopifnot(identical(table.integer64(c(1,1,2)), table(c(1,1,2)))) -#' stopifnot(identical(table.integer64(as.integer64(c(1,1,2)),c(3,4,4)), table(c(1,1,2),c(3,4,4)))) -#' stopifnot(identical(table.integer64(c(1,1,2),as.integer64(c(3,4,4))), table(c(1,1,2),c(3,4,4)))) -#' message("the following works because of ?") -#' stopifnot(identical(table(as.integer64(c(1,1,2))), table(c(1,1,2)))) -#' stopifnot(identical(table(as.integer64(c(1,1,2)),as.integer64(c(3,4,4))), table(c(1,1,2),c(3,4,4)))) -#' stopifnot(identical(table(as.integer64(c(1,1,2)),c(3,4,4)), table(c(1,1,2),c(3,4,4)))) -#' stopifnot(identical(table(c(1,1,2),as.integer64(c(3,4,4))), table(c(1,1,2),c(3,4,4)))) -#' } #' @keywords category #' @concept counts #' @concept frequencies diff --git a/man/table.integer64.Rd b/man/table.integer64.Rd index 29a2a92..ba3007f 100644 --- a/man/table.integer64.Rd +++ b/man/table.integer64.Rd @@ -112,20 +112,6 @@ table.integer64(x, y, return="data.frame") message("via as.integer64.factor we can use 'table.integer64' also for factors") table.integer64(x, as.integer64(as.factor(z))) - -\dontshow{ - stopifnot(identical(table.integer64(as.integer64(c(1,1,2))), table(c(1,1,2)))) - stopifnot(identical(table.integer64(as.integer64(c(1,1,2)),as.integer64(c(3,4,4))), table(c(1,1,2),c(3,4,4)))) - message("the following works with three warnings due to coercion") - stopifnot(identical(table.integer64(c(1,1,2)), table(c(1,1,2)))) - stopifnot(identical(table.integer64(as.integer64(c(1,1,2)),c(3,4,4)), table(c(1,1,2),c(3,4,4)))) - stopifnot(identical(table.integer64(c(1,1,2),as.integer64(c(3,4,4))), table(c(1,1,2),c(3,4,4)))) - message("the following works because of ?") - stopifnot(identical(table(as.integer64(c(1,1,2))), table(c(1,1,2)))) - stopifnot(identical(table(as.integer64(c(1,1,2)),as.integer64(c(3,4,4))), table(c(1,1,2),c(3,4,4)))) - stopifnot(identical(table(as.integer64(c(1,1,2)),c(3,4,4)), table(c(1,1,2),c(3,4,4)))) - stopifnot(identical(table(c(1,1,2),as.integer64(c(3,4,4))), table(c(1,1,2),c(3,4,4)))) -} } \seealso{ \code{\link[=table]{table()}} for more info on the standard version coping with Base R's diff --git a/tests/testthat/test-highlevel64.R b/tests/testthat/test-highlevel64.R index 05839fa..8ee61f5 100644 --- a/tests/testthat/test-highlevel64.R +++ b/tests/testthat/test-highlevel64.R @@ -100,3 +100,41 @@ test_that("sorting methods work", { expect_identical(quantile(x), q) expect_identical(quantile(x, 0.2, names=FALSE), as.integer64(21L)) }) + +# These tests were previously kept as tests under \examples{\dontshow{...}}. +# Converted to "proper" unit tests for clarity, after making them more +# canonical within {testthat}, e.g. better capturing expected warnings, +# changing stopifnot(identical(...)) to expect_identical(...). +test_that("Old \\dontshow{} tests continue working", { + xi = c(1L, 1L, 2L) + xi64 = as.integer64(xi) + yi = c(3L, 4L, 4L) + yi64 = as.integer64(yi) + + t_xi = table(x=xi) + t_xi_yi = table(x=xi, y=yi) + + expect_identical(table.integer64(x=xi64), t_xi) + expect_identical(table.integer64(x=xi64, y=yi64), t_xi_yi) + + expect_warning( + expect_identical(table.integer64(x=xi), t_xi), + "coercing first argument to integer64", + fixed = TRUE + ) + expect_warning( + expect_identical(table.integer64(x=xi64, y=yi), t_xi_yi), + "coercing argument 2 to integer64", + fixed = TRUE + ) + expect_warning( + expect_identical(table.integer64(x=xi, y=yi64), t_xi_yi), + "coercing argument 1 to integer64", + fixed = TRUE + ) + + expect_identical(table(x=xi64), t_xi) + expect_identical(table(x=xi64, y=yi64), t_xi_yi) + expect_identical(table(x=xi64, y=yi), t_xi_yi) + expect_identical(table(x=xi, y=yi64), t_xi_yi) +})