Skip to content

Commit 4f63ab0

Browse files
feat: Allow . in across() formulas (#216)
1 parent 5ae84c8 commit 4f63ab0

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

NEWS.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,16 @@
5454
* `count()` and `add_count()` now warn or error when argument `wt` is used
5555
since it is not supported. The behavior depends on the global option
5656
`tidypolars_unknown_args` (#204).
57-
57+
5858
* `tidypolars` has experimental support for fallback to R when a function is not
5959
internally translated to polars syntax. The default behavior is still to
6060
error, but the user can now set `options(tidypolars_fallback_to_r = TRUE)`
6161
to handle those unknown functions. See `?tidypolars_options` for
6262
details on the drawbacks of this approach (#205).
63-
64-
* Large performance improvement when using selection helpers (such as
63+
64+
* Large performance improvement when using selection helpers (such as
6565
`contains()`) on data with many columns (#211).
66-
66+
6767
* `tidypolars` now exports rules to be used with `flir` for detecting deprecated
6868
functions `describe_plan()` and `describe_optimized_plan()`. Those can be
6969
used in your project by following [this article](https://flir.etiennebacher.com/articles/sharing_rules#for-users).
@@ -76,6 +76,8 @@
7676

7777
* Fix error in `count()` when it includes grouping variables (#193).
7878

79+
* Passing `.` in an anonymous function in `across()` now works (#216).
80+
7981
# tidypolars 0.13.0
8082

8183
## New features

R/utils-across.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ build_separate_calls <- function(.cols, .fns, .names, .data) {
8787
}
8888

8989
arg <- sym(.cols[i])
90-
list_calls[[nm]] <- expr_substitute(.fns[[j]], quote(.x), arg)
90+
list_calls[[nm]] <- .fns[[j]] |>
91+
expr_substitute(quote(.x), arg) |>
92+
expr_substitute(quote(.), arg)
9193
}
9294
}
9395
unlist(list_calls)

tests/testthat/test-across-lazy.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@ test_that("purrr-style function work", {
4040
cyl = cyl + 1
4141
)
4242
)
43+
44+
expect_equal_lazy(
45+
mutate(
46+
test,
47+
across(.cols = contains("a"), ~ mean(.)),
48+
cyl = cyl + 1
49+
),
50+
mutate(
51+
test,
52+
drat = mean(drat),
53+
am = mean(am),
54+
gear = mean(gear),
55+
carb = mean(carb),
56+
cyl = cyl + 1
57+
)
58+
)
4359
})
4460

4561
test_that("anonymous functions has to return a Polars expression", {

tests/testthat/test-across.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ test_that("purrr-style function work", {
3636
cyl = cyl + 1
3737
)
3838
)
39+
40+
expect_equal(
41+
mutate(
42+
test,
43+
across(.cols = contains("a"), ~ mean(.)),
44+
cyl = cyl + 1
45+
),
46+
mutate(
47+
test,
48+
drat = mean(drat),
49+
am = mean(am),
50+
gear = mean(gear),
51+
carb = mean(carb),
52+
cyl = cyl + 1
53+
)
54+
)
3955
})
4056

4157
test_that("anonymous functions has to return a Polars expression", {

0 commit comments

Comments
 (0)