Skip to content

nafill() should coerce fill="2" to 2L (for example) without warning #4503

@jangorecki

Description

@jangorecki

Current behavior is like

data.table(a=1:2, b=0L)[2L, b:="2"][]
   a b
1: 1 0
2: 2 2
#Warning message:
#In `[.data.table`(data.table(a = 1:2, b = 0L), 2L, `:=`(b, "2")) :
#  Coercing 'character' RHS to 'integer' to match the type of the target column (column 2 named 'b').

There is a comment

    // this "Coercing ..." warning first to give context in case coerceVector warns 'NAs introduced by coercion'

Do we really want to raise warning here? If RHS is of not-coercible to LHS we get a warning for that

data.table(a=1:2, b=0L)[2L, b:="asd"]
#Warning messages:
#1: In `[.data.table`(data.table(a = 1:2, b = 0L), 2L, `:=`(b, "asd")) :
#  Coercing 'character' RHS to 'integer' to match the type of the target column (column 2 named 'b').
#2: In `[.data.table`(data.table(a = 1:2, b = 0L), 2L, `:=`(b, "asd")) :
#  NAs introduced by coercion

If we want to retain the warning even for coercible character, then we should add an option internally to disable that warning, so memrecycle can be used for such coercion.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions