You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Object .data[[some_string]] Is not translated correctly when used with dpyr::across in dplyr::mutate. Find below two examples: one without the use of dpyr::across that correctly translates .data[[some_string]]; and one with the use of dpyr::across that fails to correctly translate .data[[some_string]].
library(magrittr)
mtcars_db <- dbplyr::memdb_frame(mtcars)
my_col <- 'carb'
# Trivial mutating: when gear >= 4, assign NA, otherwise assign values from carb #
# Attempt 1: without dplyr::across
x1 <- mtcars_db %>%
dplyr::mutate(
x = dplyr::case_when(
gear >= 4 ~ NA,
TRUE ~ .data[[my_col]]
)
)
# Attempt 2: with dplyr::across
x2 <- mtcars_db %>%
dplyr::mutate(
dplyr::across(
dplyr::all_of(
'gear'
),
~
dplyr::case_when(
. >= 4 ~ NA,
TRUE ~ .data[[my_col]]
),
.names = 'x'
)
)
x1
# # Source: SQL [?? x 12]
# # Database: sqlite 3.46.0 [:memory:]
# mpg cyl disp hp drat wt qsec vs am gear carb x
# <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
# 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4 NA
# 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4 NA
# 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1 NA
# 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1 1
# 5 18.7 8 360 175 3.15 3.44 17.0 0 0 3 2 2
# 6 18.1 6 225 105 2.76 3.46 20.2 1 0 3 1 1
# 7 14.3 8 360 245 3.21 3.57 15.8 0 0 3 4 4
# 8 24.4 4 147. 62 3.69 3.19 20 1 0 4 2 NA
# 9 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2 NA
# 10 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4 NA
# # ℹ more rows
# # ℹ Use `print(n = ...)` to see more rows
x2
# Error in `collect()`:
# ! Failed to collect lazy table.
# Caused by error:
# ! no such column: .data.carb
# Run `rlang::last_trace()` to see where the error occurred.
In x1, .data[[my_col]] is correctly translated:
dbplyr::sql_render(x1)
# <SQL> SELECT
# `dbplyr_MemBTBwTpc`.*,
# CASE WHEN (`gear` >= 4.0) THEN NULL ELSE `carb` END AS `x`
In x2, .data[[my_col]]isn't correctly translated (see .data.carb in the SQL code):
dbplyr::sql_render(x2)
# <SQL> SELECT
# `dbplyr_MemBTBwTpc`.*,
# CASE WHEN (`gear` >= 4.0) THEN NULL ELSE (`.data`.`carb`) END AS `x`
# FROM `dbplyr_MemBTBwTpc`
The text was updated successfully, but these errors were encountered:
andreassoteriadesmoj
changed the title
Object .data[[some_string]] Is not translated correctly when used with dpyr::across in dplyr::mutate
Object .data[[some_string]] is not translated correctly when used with dpyr::across in dplyr::mutateJun 25, 2024
Object
.data[[some_string]]
Is not translated correctly when used withdpyr::across
indplyr::mutate
. Find below two examples: one without the use ofdpyr::across
that correctly translates.data[[some_string]]
; and one with the use ofdpyr::across
that fails to correctly translate.data[[some_string]]
.In
x1
,.data[[my_col]]
is correctly translated:In
x2
,.data[[my_col]]
isn't correctly translated (see.data.carb
in the SQL code):Session info:
The text was updated successfully, but these errors were encountered: