Skip to content

Automatic indexing comparing numeric with character #957

Closed

Description

@gsee

With auto.index=TRUE, attempting to compare numeric with character in the i expression throws an error.

library(data.table)
#data.table 1.9.5  For help type: ?data.table
#*** NB: by=.EACHI is now explicit. See README to restore previous behaviour.

op <- options(datatable.auto.index=FALSE) # to avoid error and see expected results
DT <- as.data.table(BOD)

DT[Time %in% c("1", "2")]
#   Time demand
#1:    1    8.3
#2:    2   10.3

DT[, Char:=as.character(Time)]
DT[Char %in% 1:2]
#   Time demand Char
#1:    1    8.3    1
#2:    2   10.3    2

options(datatable.auto.index = TRUE)
DT[Time %in% c("1", "2")]
#Error in bmerge(i, x, leftcols, rightcols, io <- FALSE, xo, roll = 0,  :
#  typeof x.Time (double) != typeof i.V1 (character)
DT[Char %in% 1:2]
#Error in bmerge(i, x, leftcols, rightcols, io <- FALSE, xo, roll = 0,  : 
#  x.'Char' is a character column being joined to i.'V1' which is type 'integer'. Character columns must join to factor or character columns.

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions