Skip to content

Allow 0 and 1 singletons to coerce to logical without warning in set() and := ? #996

@mattdowle

Description

@mattdowle

Highlighted via http://stackoverflow.com/questions/7235657/fastest-way-to-replace-nas-in-a-large-data-table/7249454?noredirect=1#comment43831879_7249454

DT = data.table(a=1:4, b=c(FALSE, TRUE, NA, FALSE))
DT
#    a     b
#1: 1 FALSE
#2: 2  TRUE
#3: 3    NA
#4: 4 FALSE
set(DT,3L,1L,0)  # ok, no warning
set(DT,3L,2L,0)  # should be ok too without warning
# Warning message:
# In set(DT, 3L, 2L, 0) :
#   Coerced 'double' RHS to 'logical' to match the column's type; may have truncated precision. Either 
# change the target column to 'double' first (by creating a new 'double' vector length 4 (nrows of entire 
# table) and assign that; i.e. 'replace' column), or coerce RHS to 'logical' (e.g. 1L, NA_[real|integer]_, as.*, 
# etc) to make your intent clear and for speed. Or, set the column type correctly up front when you create 
# the table and stick to it, please.
DT
#    a     b
#1: 1 FALSE
#2: 2  TRUE
#3: 0 FALSE
#4: 4 FALSE

Apply to 0, 1, 0L and 1L. Just length-1 vectors (i.e. singletons), not longer, as already in place for 0 and 1 to integer.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions