Skip to content

Weird consequence (bug?) of using setattr() #1281

@tdeenes

Description

@tdeenes

TRUE and FALSE are not affected by setattr(), as expected:

library(data.table)
out <- TRUE
setattr(out, "THIS", "is as expected")
out
# [1] TRUE
# attr(,"THIS")
# [1] "is as expected"
TRUE
# [1] TRUE
!FALSE
# [1] TRUE

However, consider the following (open a new console to exclude the possibility of any interference):

library(data.table)
out <- 3 > 0
out
# [1] TRUE
setattr(out, "WHY", "does it affect !FALSE?")
out # gets extra attribute, fine
# [1] TRUE
# attr(,"WHY")
# [1] "does it affect !FALSE?"
TRUE # no extra attribute, as expected
# [1] TRUE
!FALSE # ???, if TRUE is the return value of the `!` negation operator, it is "polluted"
# [1] TRUE
# attr(,"WHY")
# [1] "does it affect !FALSE?"

NOTE: the whole problem disappears if we ask for an explicit copy before the setattr() call (just insert a line: out <- copy(out) before the setattr() command).

My session info (with the very latest github version of data.table; the same problem also occurs on the CRAN version):

> sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Linux Mint LMDE

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] data.table_1.9.5

loaded via a namespace (and not attached):
[1] tools_3.2.1  chron_2.3-47

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions