Skip to content

Conversation

@hcirellu
Copy link
Contributor

@hcirellu hcirellu commented Jan 3, 2026

A generic for table is added. The table.default checks the arguments in ..., whether it contains integer64. If so, table.integer64 is called. Otherwise base::table is called.
In table.default the warnings und errors of underlying methods are captured and recreated to display nice condition messages.
table.integer64 is not exported anymore.
sortcache, sortordercache and ordercache have a new argument na.last in order to have table.integer64 consistent to base::table when it comes to NA values.
table.integer64 has two new arguments exclude and useNA to be consistent with base::table.
Where possible the translation of base-R is used for condition messages.
I added a helper function choose_sys_call() to determine the desired sys.call to be used in the condition messages.

Closes #59

@hcirellu
Copy link
Contributor Author

hcirellu commented Jan 3, 2026

As well as in #189 the warningCondition() and errorCondition() for R < 3.6.0 are missing. Should I add them here too or wait until the merge of the other PR?

@hcirellu hcirellu marked this pull request as ready for review January 3, 2026 16:32
hcirellu added a commit to hcirellu/bit64 that referenced this pull request Jan 5, 2026
hcirellu added a commit to hcirellu/bit64 that referenced this pull request Jan 5, 2026
@hcirellu
Copy link
Contributor Author

hcirellu commented Jan 9, 2026

As soon as PR #227 is merged the checks with calling optimizer64() work again.

table = function(..., exclude=if (useNA == "no") c(NA, NaN), useNA=c("no", "ifany", "always"), dnn=list.names(...), deparse.level=1L) UseMethod("table")
#' @exportS3Method table default
table.default = function(..., exclude=if (useNA == "no") c(NA, NaN), useNA=c("no", "ifany", "always"), dnn=list.names(...), deparse.level=1L) {
if (...length() && any(unlist(lapply(list(...), is.integer64)))) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (...length() && any(unlist(lapply(list(...), is.integer64)))) {
if (...length() && vapply(list(...), is.integer64, logical(1L))) {

)
}
}
choose_sys_call = function(function_names, name_to_display=NULL) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's move it to zzz.R to make the diff clearer, if any

#' @exportS3Method table default
table.default = function(..., exclude=if (useNA == "no") c(NA, NaN), useNA=c("no", "ifany", "always"), dnn=list.names(...), deparse.level=1L) {
if (...length() && any(unlist(lapply(list(...), is.integer64)))) {
withCallingHandlers({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be replaced too, right?

stop(errorCondition(gettext("all arguments must have the same length", domain="R-base"), call=choose_sys_call(c("table", "table.integer64"))))
if (!is.integer64(a)) {
warning("coercing argument ", i, " to integer64")
warning(warningCondition(paste0("coercing argument ", i, " to integer64"), call=choose_sys_call(c("table", "table.integer64"))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it required to do this? e.g., it breaks table(x, y) for y a string.

We can mark this as a follow-up, checking your thoughts here first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

table(x) is not given an S3 generic overwrite

2 participants