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

eval() not working with := syntax #4914

Closed
GitHunter0 opened this issue Feb 21, 2021 · 1 comment
Closed

eval() not working with := syntax #4914

GitHunter0 opened this issue Feb 21, 2021 · 1 comment
Labels
programming parameterizing queries: get, mget, eval, env

Comments

@GitHunter0
Copy link

GitHunter0 commented Feb 21, 2021

library(data.table)
new_col <- "test_col"
DT <- data.table(x=1:3)

This works:

DT[, eval(new_col) := x][]

This also works:

DT[, ':=' ("test_col" = x)][]

But this throws "Error: unexpected '=' in "DT[, := (eval(new_col) =" :

DT[, `:=` (eval(new_col) = x)][]
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

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

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

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5          
 [2] compiler_4.0.3      
 [3] prettyunits_1.1.1   
 [4] remotes_2.2.0       
 [5] tools_4.0.3         
 [6] testthat_2.3.2      
 [7] digest_0.6.27       
 [8] pkgbuild_1.2.0      
 [9] pkgload_1.1.0       
[10] evaluate_0.14       
[11] jsonlite_1.7.0      
[12] memoise_1.1.0       
[13] lattice_0.20-41     
[14] rlang_0.4.10        
[15] Matrix_1.2-18       
[16] cli_2.2.0           
[17] rstudioapi_0.13     
[18] yaml_2.2.1          
[19] xfun_0.19           
[20] withr_2.3.0         
[21] knitr_1.30          
[22] desc_1.2.0          
[23] fs_1.5.0            
[24] devtools_2.3.1      
[25] rprojroot_2.0.2     
[26] grid_4.0.3          
[27] reticulate_1.16     
[28] glue_1.4.2          
[29] R6_2.5.0            
[30] processx_3.4.5      
[31] fansi_0.4.1         
[32] rmarkdown_2.6       
[33] librarian_1.7.2     
[34] sessioninfo_1.1.1   
[35] callr_3.4.3         
[36] magrittr_2.0.1      
[37] htmltools_0.5.0.9003
[38] ps_1.5.0            
[39] ellipsis_0.3.1      
[40] usethis_1.6.1       
[41] assertthat_0.2.1    
[42] crayon_1.3.4   
@MichaelChirico
Copy link
Member

you can't set the names in a call like this. the issue here will be solved when #4304 is merged; closing here for now.

BTW the usual way would be

DT[, (new_col) := ...]

@jangorecki jangorecki added the programming parameterizing queries: get, mget, eval, env label Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
programming parameterizing queries: get, mget, eval, env
Projects
None yet
Development

No branches or pull requests

3 participants