Skip to content

Commit 23a15cd

Browse files
Handle dot-prefixed names in custom translation (#1530)
--------- Co-authored-by: Hadley Wickham <[email protected]>
1 parent 3730c70 commit 23a15cd

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# dbplyr (development version)
22

3+
* Custom translations of functions starting with `.` work (@MichaelChirico, #1529).
34
* SQL Server 2025 (version 17.0) now supports stringr regex functions: `str_detect()`, `str_starts()`, `str_ends()`, `str_replace()`, `str_replace_all()`, `str_remove()`, `str_remove_all()`, `str_extract()`, and `str_count()`. Fixed pattern versions of `str_detect()`, `str_starts()`, and `str_ends()` work on all SQL Server versions (#1671).
45
* MS Access now correctly generates SQL for multiple joins by adding required parentheses (#1576).
56
* `.data$col`, `.data[[col]]`, `.env$var`, and `.env$[[var]]` now work correctly inside `across()` (#1520).

R/tidyeval.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ find_fun <- function(fun) {
290290
fun_name <- function(fun) {
291291
# `dtplyr` uses the same idea but needs different environments
292292
pkg_env <- env_parent(global_env())
293-
known <- c(ls(base_agg), ls(base_scalar))
293+
known <- c(env_names(base_agg), env_names(base_scalar))
294294

295295
for (x in known) {
296296
if (!env_has(pkg_env, x, inherit = TRUE)) {

R/translate-sql-helpers.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,18 @@ sql_variant <- function(
6464
check_environment(window)
6565

6666
# Need to check that every function in aggregate also occurs in window
67-
missing <- setdiff(ls(aggregate), ls(window))
67+
missing <- setdiff(env_names(aggregate), env_names(window))
6868
if (length(missing) > 0) {
6969
warn(paste0(
7070
"Translator is missing window variants of the following aggregate functions:\n",
7171
paste0("* ", missing, "\n", collapse = "")
7272
))
7373
}
7474

75-
aggregate_fns <- ls(envir = aggregate)
75+
aggregate_fns <- env_names(aggregate)
7676

7777
# An ensure that every window function is flagged in aggregate context
78-
missing <- setdiff(ls(window), ls(aggregate))
78+
missing <- setdiff(env_names(window), env_names(aggregate))
7979
missing_funs <- lapply(missing, sql_aggregate_win)
8080
env_bind(aggregate, !!!set_names(missing_funs, missing))
8181

@@ -95,7 +95,7 @@ is.sql_variant <- function(x) inherits(x, "sql_variant")
9595
#' @export
9696
print.sql_variant <- function(x, ...) {
9797
wrap_ls <- function(x, ...) {
98-
vars <- sort(ls(envir = x))
98+
vars <- sort(env_names(x))
9999
wrapped <- strwrap(paste0(vars, collapse = ", "), ...)
100100
if (identical(wrapped, "")) {
101101
return()
@@ -120,7 +120,7 @@ print.sql_variant <- function(x, ...) {
120120

121121
#' @export
122122
names.sql_variant <- function(x) {
123-
c(ls(envir = x$scalar), ls(envir = x$aggregate), ls(envir = x$window))
123+
c(env_names(x$scalar), env_names(x$aggregate), env_names(x$window))
124124
}
125125

126126
#' @export

R/translate-sql-window.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ uses_window_fun <- function(x, con, lq) {
403403
check_list(x)
404404

405405
calls <- unlist(lapply(x, all_calls))
406-
win_f <- ls(envir = dbplyr_sql_translation(con)$window)
406+
win_f <- env_names(dbplyr_sql_translation(con)$window)
407407
any(calls %in% win_f)
408408
}
409409

@@ -430,7 +430,7 @@ is_aggregating <- function(x, non_group_cols, agg_f) {
430430
}
431431

432432
common_window_funs <- function() {
433-
ls(dbplyr_sql_translation(NULL)$window) # nocov
433+
env_names(dbplyr_sql_translation(NULL)$window) # nocov
434434
}
435435

436436
#' @noRd

R/verb-filter.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ add_filter <- function(.data, dots) {
8484
# Do partial evaluation, then extract out window functions
8585
where <- translate_window_where_all(
8686
dots,
87-
ls(dbplyr_sql_translation(con)$window)
87+
env_names(dbplyr_sql_translation(con)$window)
8888
)
8989

9090
# Add extracted window expressions as columns

0 commit comments

Comments
 (0)