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
While base R handles it correctly
Related to this SO answer