Skip to content

Should nafill/setnafill allow coercsion and/or have more verbose warning messages? #7757

Description

@KyleHaynes

Thrilled that setnafill, nafill has been extended to other class types, however, should (or could) it allow for coercion of the var type when filling to another class?

e.g.

install.packages("data.table", repos="https://rdatatable.gitlab.io/data.table")
require(data.table)

dt = data.table(char = c("",NA,"blah","food"), num = c(NA,1,2,NA))
dt
#      char   num
#    <char> <num>
# 1:           NA
# 2:   <NA>     1
# 3:   blah     2
# 4:   food    NA

setnafill(dt, fill = "")
dt
# Warning message:
# In setnafill(dt, fill = "") :
#   Coercing 'character' RHS to 'double' to match the type of target vector.
dt
#      char   num
#    <char> <num>
# 1:           NA
# 2:            1
# 3:   blah     2
# 4:   food    NA

At the moment, it obviously doesn't coerce, but the warning is not overly helpful, could it be improved by specifying which vars were not coerced?

Activity

  1. jangorecki commented on May 23, 2026

    @jangorecki
    Member

    For setnafill I don't think it should coerce because it needs new allocation

  2. ben-schwen commented on May 26, 2026

    @ben-schwen
    Member

    I agree that the warning isn’t particularly helpful and that we should improve it.

    However, I am not really convinced that we should allow or implement type conversion for the fill argument. The simplest example is probably that many users in R use integer and double interchangeably, and this even made worse for example that the storage type in Date or PosixCT is not unambiguous.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions