Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRUE/FALSE and abbreviated variants T/F have different behavior when used in j #4846

Open
eaurele opened this issue Dec 15, 2020 · 2 comments · May be fixed by #6196
Open

TRUE/FALSE and abbreviated variants T/F have different behavior when used in j #4846

eaurele opened this issue Dec 15, 2020 · 2 comments · May be fixed by #6196

Comments

@eaurele
Copy link

eaurele commented Dec 15, 2020

When using a logical vector in j to select columns dynamically (StackOverflow), using the abbreviations T/F has different behavior than using TRUE/FALSE

# Minimal reproducible example

library(data.table)
#> Warning: package 'data.table' was built under R version 4.0.3

DT = data.table(x=rep(c("a","b","c"),each=3), y=c(1,3,6), v=1:9)
DT[, c(TRUE, TRUE, FALSE), verbose = TRUE]
#>    x y
#> 1: a 1
#> 2: a 3
#> 3: a 6
#> 4: b 1
#> 5: b 3
#> 6: b 6
#> 7: c 1
#> 8: c 3
#> 9: c 6
DT[, c(T, T, F), verbose = TRUE]
#> Detected that j uses these columns: <none>
#> [1]  TRUE  TRUE FALSE

# `with = FALSE` still works as expected, though should no longer be necessary
# per https://stackoverflow.com/a/33301945/6197649
DT[, c(T, T, F), with = FALSE, verbose = TRUE]
#>    x y
#> 1: a 1
#> 2: a 3
#> 3: a 6
#> 4: b 1
#> 5: b 3
#> 6: b 6
#> 7: c 1
#> 8: c 3
#> 9: c 6

# Output of sessionInfo()

sessionInfo()
#> R version 4.0.2 (2020-06-22)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 18363)
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=English_Europe.1252  LC_CTYPE=English_Europe.1252   
#> [3] LC_MONETARY=English_Europe.1252 LC_NUMERIC=C                   
#> [5] LC_TIME=English_Europe.1252    
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] data.table_1.13.4
#> 
#> loaded via a namespace (and not attached):
#>  [1] compiler_4.0.2  magrittr_1.5    tools_4.0.2     htmltools_0.5.0
#>  [5] yaml_2.2.1      stringi_1.4.6   rmarkdown_2.3   highr_0.8      
#>  [9] knitr_1.29      stringr_1.4.0   xfun_0.16       digest_0.6.25  
#> [13] rlang_0.4.7     evaluate_0.14

Created on 2020-12-15 by the reprex package (v0.3.0)

@eaurele eaurele changed the title TRUE/FALSE and their abbreviated variants T/F have different behavior when used in j TRUE/FALSE and abbreviated variants T/F have different behavior when used in j Dec 15, 2020
@jangorecki
Copy link
Member

jangorecki commented Dec 16, 2020

Could eventually be related: https://stat.ethz.ch/pipermail/r-devel/2020-December/080317.html as we do use all.vars

> all.vars(quote(c(T,F)))
[1] "T" "F"
> all.vars(quote(c(TRUE,FALSE)))
character(0)

making workaround for that in data.table will probably be tricky because there might be T/F fields in data.table, or user defined variables in parent scope.

@MichaelChirico
Copy link
Member

Agree w Jan -- don't use T and F is the best recommendation IMO. Probably this could be documented somewhere, maybe FAQ?

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

Successfully merging a pull request may close this issue.

3 participants