Skip to content

set triggers a strange warning when adding a NA to a factor column by reference #1234

Closed

Description

@DavidArenburg
library(data.table) ## v1.9.5+
data = data.frame(cats = rep(c('', ' ',  'meow'), 5))
set(data, i = grep("^$|^ $", data[[1]]), j = 1L, value = NA_integer_)
# Warning message:
#   In set(data, i = grep("^$|^ $", data[[j]]), j = 1L, value = NA_integer_) :
#   RHS contains -2147483648 which is outside the levels range ([1,3]) of column 1, NAs generated

While base R handles it correctly

data = data.frame(cats = rep(c('', ' ',  'meow'), 5))
indx <- grep("^$|^ $", data$cats)
data$cats[indx] <- NA_integer_

Related to this SO answer

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