Skip to content

Commit

Permalink
run correctly even when is.atomic(NULL) becomes FALSE (#5691)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaechler authored Nov 5, 2023
1 parent 94e8fbe commit e66f5dc
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ replace_dot_alias = function(e) {
bynames = allbyvars = NULL
# the rest now fall through
} else bynames = names(byval)
if (is.atomic(byval)) {
if (is.atomic(byval) || is.null(byval)) {
if (is.character(byval) && length(byval)<=ncol(x) && !(is.name(bysub) && bysub %chin% names_x) ) {
stopf("'by' appears to evaluate to column names but isn't c() or key(). Use by=list(...) if you can. Otherwise, by=eval%s should work. This is for efficiency so data.table can detect which columns are needed.", deparse(bysub))
} else {
Expand Down
2 changes: 1 addition & 1 deletion R/frank.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ frankv = function(x, cols=seq_along(x), order=1L, na.last=TRUE, ties.method=c("a
.Call(Csetlistelt, xx, 1L, x)
xx
}
if (is.atomic(x)) {
if (is.atomic(x) || is.null(x)) {
if (!missing(cols) && !is.null(cols))
stopf("x is a single vector, non-NULL 'cols' doesn't make sense")
cols = 1L
Expand Down
2 changes: 1 addition & 1 deletion R/fread.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ yaml=FALSE, autostart=NA, tmpdir=tempdir(), tz="UTC")
if (!allNA(colClasses)) stopf("colClasses is type 'logical' which is ok if all NA but it has some TRUE or FALSE values in it which is not allowed. Please consider the drop= or select= argument instead. See ?fread.")
colClasses = NULL
}
if (!is.null(colClasses) && is.atomic(colClasses)) {
if (!is.null(colClasses) && is.atomic(colClasses)) { ## future R can use if (is.atomic(.))
if (!is.character(colClasses)) stopf("colClasses is not type list or character vector")
if (!length(colClasses)) {
colClasses=NULL;
Expand Down
3 changes: 2 additions & 1 deletion R/print.data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"),
}

format.data.table = function (x, ..., justify="none") {
if (is.atomic(x) && !is.null(x)) {
if (is.atomic(x) && !is.null(x)) { ## future R can use if (is.atomic(x))

stopf("Internal structure doesn't seem to be a list. Possibly corrupt data.table.")
}
do.call("cbind", lapply(x, format_col, ..., justify=justify))
Expand Down
2 changes: 1 addition & 1 deletion R/setkey.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ is.sorted = function(x, by=NULL) {
ORDERING_TYPES = c('logical', 'integer', 'double', 'complex', 'character')
forderv = function(x, by=seq_along(x), retGrp=FALSE, sort=TRUE, order=1L, na.last=FALSE)
{
if (is.atomic(x)) { # including forderv(NULL) which returns error consistent with base::order(NULL),
if (is.atomic(x) || is.null(x)) { # including forderv(NULL) which returns error consistent with base::order(NULL),
if (!missing(by) && !is.null(by)) stopf("x is a single vector, non-NULL 'by' doesn't make sense")
by = NULL
} else {
Expand Down

0 comments on commit e66f5dc

Please sign in to comment.