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

chore: Prepare for removal of magrittr imports #1983

Merged
merged 2 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/build_copy_queries.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ build_copy_queries <- function(dest, dm, set_key_constraints = TRUE, temporary =
# database-specific autoincrementing column types
if (length(pk_col) > 0L) {
# extract column name representing primary key
pk_col <- pk_col %>% extract2(1L)
pk_col <- pk_col[[1]]

# Postgres:
if (is_postgres(dest)) {
Expand Down
5 changes: 1 addition & 4 deletions R/flatten.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,7 @@ dm_flatten_to_tbl_impl <- function(dm, start, list_of_pts, join, join_name, squa
order_df <- left_join(tibble(name = unname(list_of_pts)), order_df, by = "name")

# list of join partners
ordered_table_list <-
prep_dm %>%
dm_get_tables() %>%
extract(order_df$name)
ordered_table_list <- dm_get_tables(prep_dm)[order_df$name]
by <- map2(order_df$pred, order_df$name, ~ get_by(prep_dm, .x, .y))

# perform the joins according to the list, starting with table `initial_LHS`
Expand Down
8 changes: 2 additions & 6 deletions R/table-surgery.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,9 @@ reunite_parent_child_from_list <- function(list_of_parent_child_tables, id_colum
id_col_chr <-
as_name(id_col_q)

child_table <-
list_of_parent_child_tables %>%
extract2("child_table")
child_table <- list_of_parent_child_tables[["child_table"]]

parent_table <-
list_of_parent_child_tables %>%
extract2("parent_table")
parent_table <- list_of_parent_child_tables[["parent_table"]]

child_table %>%
left_join(parent_table, by = id_col_chr) %>%
Expand Down
26 changes: 15 additions & 11 deletions tests/testthat/_snaps/code-generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,27 @@
mtcars, penguins)))
Output
[1] "dm_add_tbl(weather, airports, flights, airlines, planes, mtcars, penguins)"

---

Code
new_cg_block()
new_cg_block(quo(dm_nycflights13()), list(function(.) dm_add_pk(., flights,
flight_id)))
Output
dm_nycflights13() %>%
dm_add_pk(flights, flight_id)

---

Code
table <- "flights"
columns <- "carrier"
cg_block <- new_cg_block(quo(dm_nycflights13())) %>% cg_add_call(dm_rm_fk(.,
table = !!ensym(table), columns = !!ensym(columns), ref_table = airlines)) %>%
table = !!sym(table), columns = !!sym(columns), ref_table = airlines)) %>%
cg_add_call(dm_rm_fk(., table = flights, columns = c(origin, time_hour),
ref_table = weather)) %>% cg_add_call(dm_add_fk(., table = !!ensym(table),
columns = !!ensym(columns), ref_table = airlines))
ref_table = weather)) %>% cg_add_call(dm_add_fk(., table = !!sym(table),
columns = !!sym(columns), ref_table = airlines))
cg_block
Output
dm_nycflights13() %>%
Expand All @@ -38,21 +44,19 @@
Columns: 53
Primary keys: 4
Foreign keys: 3

---

Code
cg_block_2 <- new_cg_block(cg_block$cg_input_object, list(function(.)
dm_add_tbl(., mtcars), function(.) dm_select_tbl(., -planes)))
cg_block_2 <- new_cg_block(cg_block$cg_input_object, list(function(.) dm(.,
mtcars), function(.) dm_select_tbl(., -planes)))
cg_block_2
Output
dm_nycflights13() %>%
dm_add_tbl(mtcars) %>%
dm(mtcars) %>%
dm_select_tbl(-planes)
Code
cg_eval_block(cg_block_2)
Condition
Warning:
`dm_add_tbl()` was deprecated in dm 1.0.0.
i Please use `dm()` instead.
i Use `.name_repair = "unique"` if necessary.
Output
-- Metadata --------------------------------------------------------------------
Tables: `airlines`, `airports`, `flights`, `weather`, `mtcars`
Expand Down
15 changes: 12 additions & 3 deletions tests/testthat/test-code-generation.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,29 @@ test_that("code generation works", {
expect_snapshot({
call_to_char(body(function(.) dm_add_tbl(., weather)))
call_to_char(expr(dm_add_tbl(., weather, airports, flights, airlines, planes, mtcars, penguins)))
})

expect_snapshot({
new_cg_block()
new_cg_block(quo(dm_nycflights13()), list(function(.) dm_add_pk(., flights, flight_id)))
})

expect_snapshot({
table <- "flights"
columns <- "carrier"
cg_block <- new_cg_block(quo(dm_nycflights13())) %>%
cg_add_call(dm_rm_fk(., table = !!ensym(table), columns = !!ensym(columns), ref_table = airlines)) %>%
cg_add_call(dm_rm_fk(., table = !!sym(table), columns = !!sym(columns), ref_table = airlines)) %>%
cg_add_call(dm_rm_fk(., table = flights, columns = c(origin, time_hour), ref_table = weather)) %>%
cg_add_call(dm_add_fk(., table = !!ensym(table), columns = !!ensym(columns), ref_table = airlines))
cg_add_call(dm_add_fk(., table = !!sym(table), columns = !!sym(columns), ref_table = airlines))
cg_block
cg_eval_block(cg_block)
})

expect_snapshot({
cg_block_2 <- new_cg_block(
cg_block$cg_input_object,
list(
function(.) dm_add_tbl(., mtcars),
function(.) dm(., mtcars),
function(.) dm_select_tbl(., -planes)
)
)
Expand Down
Loading