From 88102734a94992ee222dc97740f99b744b54292f Mon Sep 17 00:00:00 2001 From: hcirellu Date: Fri, 14 Nov 2025 20:51:08 +0100 Subject: [PATCH] as.integer64.integer64 now stripps all atributes --- NEWS.md | 3 +++ R/integer64.R | 10 +++++++++- tests/testthat/test-integer64.R | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 056cc06..186d2a6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -39,6 +39,8 @@ Because there was no recorded direct usage for any of these, I am opting to just rip the band-aid off and un-export them in this release as opposed to waiting a full cycle more to do so. +1. `as.integer64.integer64` returns a plain `integer64` vector stripped by any attributes. This is consistent with R like behavior e.g. `as.integer.integer`. + ## NEW FEATURES 1. `anyNA` gets an `integer64` method. Thanks @hcirellu. @@ -46,6 +48,7 @@ ## BUG FIXES 1. `min.integer64`, `max.integer64` and `range.integer64` now support `na.rm=TRUE` correctly when combining across mutliple inputs like `min(x, NA_integer64_, na.rm=TRUE)` (#142). +1. `as.integer64.integer64` is consistent with R like behavior like `as.integer.integer` in terms or returning a plain integer64 vector (#188). ## NOTES diff --git a/R/integer64.R b/R/integer64.R index 46c70a1..01e5122 100644 --- a/R/integer64.R +++ b/R/integer64.R @@ -672,7 +672,15 @@ as.integer64.NULL <- function(x, ...) { #' @rdname as.integer64.character #' @export -as.integer64.integer64 <- function(x, ...) x +as.integer64.integer64 = function(x, ...) { + ret = unclass(x) + attributes(ret) = NULL + # if keep.names is added as argument + # if (isTRUE(keep.names)) + # names(ret) = names(x) + oldClass(ret) = "integer64" + ret +} #' @rdname as.integer64.character #' @export diff --git a/tests/testthat/test-integer64.R b/tests/testthat/test-integer64.R index c66d8d3..b8204c7 100644 --- a/tests/testthat/test-integer64.R +++ b/tests/testthat/test-integer64.R @@ -11,8 +11,8 @@ test_that("integer64 coercion to/from other types work", { expect_identical(as.integer64(as.character(1:10)), as.integer64(1:10)) expect_identical(as.integer64(as.double(1:10)), as.integer64(1:10)) expect_identical(as.integer64(NULL), as.integer64()) - x = as.integer64(1:10) - expect_identical(as.integer64(x), x) + x = structure(as.integer64(1:10), class=c("otherClass", "integer64"), dim=c(2, 5), dimnames=list(LETTERS[1:2], letters[1:5]), otherAttr="some other attribute") + expect_identical(as.integer64(x), as.integer64(1:10)) # S4 version expect_identical(methods::as(as.character(1:10), "integer64"), as.integer64(1:10))