From e8abbb8af19d9517a451fd402118e409c1a690b8 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Fri, 27 Mar 2026 21:17:53 +0000 Subject: [PATCH 1/3] Adapt to utils:::print.bitstring --- NAMESPACE | 1 - NEWS.md | 3 ++- R/integer64.R | 9 ++------- R/zzz.R | 14 +++++++++++++- tests/testthat/test-integer64.R | 4 ++++ 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index d80abdf4..1b036627 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -130,7 +130,6 @@ S3method(ordertie,integer64) S3method(orderuni,integer64) S3method(orderupo,integer64) S3method(prank,integer64) -S3method(print,bitstring) S3method(print,cache) S3method(print,integer64) S3method(prod,integer64) diff --git a/NEWS.md b/NEWS.md index c58f5e2b..302add15 100644 --- a/NEWS.md +++ b/NEWS.md @@ -82,7 +82,8 @@ ## NOTES 1. {bit64} no longer prints any start-up messages through an `.onAttach()` hook (#106). Thanks @hadley for the request. -2. The R version dependency has been bumped from 3.4.0 (2017) to 3.5.0 (2018). +1. The R version dependency has been bumped from 3.4.0 (2017) to 3.5.0 (2018). +1. From R 4.6.0, R's {utils} package has its own 'bitstring' class which is basically compatible with that shipped by {bit64} for many years. `as.bitstring()` only makes a simple adjustment, namely, for `as.bitstring()` to add two new attributes (`nbits` and `type`). Everything else should continue to work as before. ## BUG FIXES diff --git a/R/integer64.R b/R/integer64.R index 8537ab53..3c7ee800 100644 --- a/R/integer64.R +++ b/R/integer64.R @@ -695,6 +695,8 @@ as.character.integer64 = function(x, ...) as.bitstring.integer64 = function(x, ...) { ret = .Call(C_as_bitstring_integer64, x, rep(NA_character_, length(x))) oldClass(ret) = 'bitstring' + attr(ret, 'nbits') = c(1L, 63L) + attr(ret, 'type') = "int64" ret } @@ -780,13 +782,6 @@ factor = function(x=character(), levels, labels=levels, exclude=NA, ordered=is.o #' @export ordered = function(x=character(), ...) factor(x, ..., ordered=TRUE) -#' @rdname as.character.integer64 -#' @export -print.bitstring = function(x, ...) { - oldClass(x) = minusclass(class(x), 'bitstring') - NextMethod(x) -} - #' @rdname as.integer64.character #' @export as.integer64.bitstring = function(x, ...) { diff --git a/R/zzz.R b/R/zzz.R index 51f59bd1..afecbc25 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -15,7 +15,7 @@ if (getRversion() < "3.6.0") { class(obj) = c(class, "error", "condition") obj } - + warningCondition = function(message, ..., class = NULL, call = NULL) { obj <- list(message = as.character(message), call = call, ...) class(obj) = c(class, "warning", "condition") @@ -23,6 +23,18 @@ if (getRversion() < "3.6.0") { } } +.onLoad = function(libname, pkgname) { + # TODO(R >= 4.6.0): remove this. + if (!utils::isS3method("print.bitstring")) { + registerS3method("print", "bitstring", function(x, ...) { + reset_class = minusclass(class(x), 'bitstring') + attributes(x) = NULL + oldClass(x) = reset_class + NextMethod(x) + }) + } +} + .onAttach = function(libname, pkgname) { packageStartupMessage( # in **bold** "\033[1mThe assignment of character values to integer64 vectors and ", diff --git a/tests/testthat/test-integer64.R b/tests/testthat/test-integer64.R index bc36015d..11215f09 100644 --- a/tests/testthat/test-integer64.R +++ b/tests/testthat/test-integer64.R @@ -1573,3 +1573,7 @@ test_that("back-compatible keep.names=TRUE is supported for limited input classe y = c(a = 1.0) expect_named(as.integer64(y, keep.names=TRUE), "a") }) + +test_that("bitstring class meshes with R's own (from 4.6.0)", { + expect_no_error(print(as.bitstring(lim.integer64()))) +}) From 12bd40bf9a70a3fda5857b92283e41fdc85c555a Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Fri, 27 Mar 2026 21:23:20 +0000 Subject: [PATCH 2/3] expect_no_error for ancient --- .devcontainer/r-350/.Rprofile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.devcontainer/r-350/.Rprofile b/.devcontainer/r-350/.Rprofile index d4e64580..a49336cc 100644 --- a/.devcontainer/r-350/.Rprofile +++ b/.devcontainer/r-350/.Rprofile @@ -98,11 +98,17 @@ expect_no_warning <- function(object, ...) { } expect_error = function(expr, msg, ...) { - val = tryCatch(expr, error = identity) + val = tryCatch(expr, error=identity) stopifnot(inherits(val, "error") && grepl(msg, conditionMessage(val), ...)) cat(".") } +expect_no_error = function(expr) { + val = tryCatch(expr, error=identity) + stopifnot(!inherits(val, "error")) + cat(".") +} + expect_s3_class = function(x, kls) { stopifnot(inherits(x, kls)); cat(".") } expect_length = function(x, l) expect_identical(length(x), l) From 1b0e693d776e6baff877921b32f883f9fc1dbddf Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Fri, 27 Mar 2026 21:30:49 +0000 Subject: [PATCH 3/3] remove .Rd references --- man/as.character.integer64.Rd | 3 --- 1 file changed, 3 deletions(-) diff --git a/man/as.character.integer64.Rd b/man/as.character.integer64.Rd index 769ce956..391a6140 100644 --- a/man/as.character.integer64.Rd +++ b/man/as.character.integer64.Rd @@ -15,7 +15,6 @@ \alias{as.POSIXlt.integer64} \alias{as.factor} \alias{as.ordered} -\alias{print.bitstring} \alias{as.list.integer64} \title{Coerce from integer64} \usage{ @@ -47,8 +46,6 @@ as.factor(x) as.ordered(x) -\method{print}{bitstring}(x, ...) - \method{as.list}{integer64}(x, ...) } \arguments{