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

Dot dot prefix with expression instead of symbol #2851

Closed
christianhomberg opened this issue May 8, 2018 · 3 comments
Closed

Dot dot prefix with expression instead of symbol #2851

christianhomberg opened this issue May 8, 2018 · 3 comments
Labels
programming parameterizing queries: get, mget, eval, env

Comments

@christianhomberg
Copy link

christianhomberg commented May 8, 2018

I like the .. notation (new feature #18 in https://github.com/Rdatatable/data.table/blob/master/NEWS.md) and the idea of eventually replacing with = F. For now, I can't find a way to get around with = F when using expressions in j, e.g.:

require(magrittr)
require(data.table)

iris_dt = iris %>% setDT
iris_cols = iris_dt %>% colnames
iris_dt[, iris_cols %>% first, with = F]

I tried unsuccessfully and would suggest one of the following syntax:

iris_dt[, ..(iris_cols %>% first)]
iris_dt[, ..{iris_cols %>% first}]
Output of sessionInfo(): ``` R version 3.4.4 (2018-03-15) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 18.04 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale:
[1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C LC_TIME=en_GB.UTF-8
[4] LC_COLLATE=en_GB.UTF-8 LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8
[7] LC_PAPER=en_GB.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] markovchain_0.6.9.8-1 shiny_1.0.5 data.table_1.11.0 magrittr_1.5
[5] ggplot2_2.2.1

loaded via a namespace (and not attached):
[1] Rcpp_0.12.16 compiler_3.4.4 pillar_1.2.2 later_0.7.2
[5] plyr_1.8.4 tools_3.4.4 digest_0.6.15 packrat_0.4.9-2
[9] lattice_0.20-35 jsonlite_1.5 evaluate_0.10.1 tibble_1.4.2
[13] gtable_0.2.0 pkgconfig_2.0.1 rlang_0.2.0.9001 Matrix_1.2-14
[17] igraph_1.2.1 parallel_3.4.4 yaml_2.1.19 expm_0.999-2
[21] stringr_1.3.0 knitr_1.20 stats4_3.4.4 rprojroot_1.3-2
[25] grid_3.4.4 flexdashboard_0.5.1 R6_2.2.2 rmarkdown_1.9
[29] matlab_1.0.2 purrr_0.2.4 codetools_0.2-15 backports_1.1.2
[33] scales_0.5.0 promises_1.0.1 htmltools_0.3.6 mime_0.5
[37] xtable_1.8-2 colorspace_1.3-2 httpuv_1.4.2 stringi_1.2.2
[41] RcppParallel_4.4.0 lazyeval_0.2.1 munsell_0.4.3

</details>
@jangorecki
Copy link
Member

Related #2826

@MichaelChirico
Copy link
Member

MichaelChirico commented May 9, 2018

I really like the way that looks, but unfortunately it won't parse (so AFAICT it's impossible to work)

Comparse substitute(..var_name) (fine) with substitute(..{expression}) (errors: "unexpected {")

..(expression) will parse... might be easier to test whether to evaluate through is.call as well. Doesn't look as natural as ..{} IMO

@jangorecki
Copy link
Member

Using the api proposed in #4304 this operation could be generalized into

iris_dt[, v, env = list(v = I(first(iris_cols)))]

# then it will work as
iris_dt[, "Sepal.Length"]
# if you will skip `I()` call above then it will get translated into
iris_dt[, Sepal.Length]

As there is no way to handle ..{} I think we can close your request now, eventually ..() could be supported in future.

@jangorecki jangorecki added the programming parameterizing queries: get, mget, eval, env label Apr 6, 2020
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