# select after distinct produces subquery Code lf %>% distinct() %>% select(x) Output SELECT `x` FROM ( SELECT DISTINCT `df`.* FROM `df` ) AS `q01` # rename/relocate after distinct is inlined #1141 Code lf %>% distinct() %>% rename(z = y) Output SELECT DISTINCT `x`, `y` AS `z` FROM `df` Code lf %>% distinct() %>% relocate(y) Output SELECT DISTINCT `y`, `x` FROM `df` # select preserves grouping vars Code out <- mf %>% select(a) %>% collect() Message Adding missing grouping variables: `b` # select() after left_join() is inlined Code (out <- left_join(lf1, lf2, by = "x") %>% select(b, x)) Output SELECT `b`, `lf1`.`x` AS `x` FROM `lf1` LEFT JOIN `lf2` ON (`lf1`.`x` = `lf2`.`x`) --- Code (out <- left_join(lf1, lf2, by = "x") %>% relocate(b)) Output SELECT `b`, `lf1`.* FROM `lf1` LEFT JOIN `lf2` ON (`lf1`.`x` = `lf2`.`x`) # select() after semi_join() is inlined Code (out <- semi_join(lf1, lf2, by = "x") %>% select(x, a2 = a)) Output SELECT `x`, `a` AS `a2` FROM `lf1` WHERE EXISTS ( SELECT 1 FROM `lf2` WHERE (`lf1`.`x` = `lf2`.`x`) ) --- Code (out <- anti_join(lf1, lf2, by = "x") %>% relocate(a)) Output SELECT `a`, `x` FROM `lf1` WHERE NOT EXISTS ( SELECT 1 FROM `lf2` WHERE (`lf1`.`x` = `lf2`.`x`) ) # select() after join handles previous select Code print(lf) Output SELECT `x` AS `x2`, `y` AS `y3`, `z` FROM `df` AS `df_LHS` WHERE EXISTS ( SELECT 1 FROM `df` AS `df_RHS` WHERE (`df_LHS`.`x` = `df_RHS`.`x`) ) --- Code print(lf2) Output SELECT `df_LHS`.`x` AS `x2`, `df_LHS`.`y` AS `y3`, `z` FROM `df` AS `df_LHS` LEFT JOIN `df` AS `df_RHS` ON (`df_LHS`.`x` = `df_RHS`.`x`) # select() produces nice error messages Code lf %>% select(non_existent) Condition Error in `select()`: ! Can't subset columns that don't exist. x Column `non_existent` doesn't exist. Code lf %>% select(non_existent + 1) Condition Error in `select()`: ! Problem while evaluating `non_existent + 1`. Caused by error: ! object 'non_existent' not found --- Code lf %>% relocate(non_existent) Condition Error in `relocate()`: ! Can't subset columns that don't exist. x Column `non_existent` doesn't exist. Code lf %>% relocate(non_existent + 1) Condition Error in `relocate()`: ! Problem while evaluating `non_existent + 1`. Caused by error: ! object 'non_existent' not found --- Code lf %>% rename(x) Condition Error in `rename()`: ! All renaming inputs must be named. Code lf %>% rename(y = non_existent) Condition Error in `rename()`: ! Can't rename columns that don't exist. x Column `non_existent` doesn't exist. Code lf %>% rename(y = non_existent + 1) Condition Error in `rename()`: ! Problem while evaluating `non_existent + 1`. Caused by error: ! object 'non_existent' not found --- Code lf %>% rename_with(toupper, .cols = non_existent) Condition Error in `rename_with()`: ! Can't subset columns that don't exist. x Column `non_existent` doesn't exist. Code lf %>% rename_with(toupper, .cols = non_existent + 1) Condition Error in `rename_with()`: ! Problem while evaluating `non_existent + 1`. Caused by error: ! object 'non_existent' not found # where() isn't suppored Code lf %>% select(where(is.integer)) Condition Error in `select()`: ! This tidyselect interface doesn't support predicates. # multiple selects are collapsed Code lf %>% select(2:1) %>% select(2:1) Output SELECT `df`.* FROM `df` --- Code lf %>% select(2:1) %>% select(2:1) %>% select(2:1) Output SELECT `y`, `x` FROM `df` --- Code lf %>% select(x1 = x) %>% select(x2 = x1) Output SELECT `x` AS `x2` FROM `df` # mutate collapses over nested select Code lf %>% mutate(a = 1, b = 2) %>% select(a) Output SELECT 1.0 AS `a` FROM `df` --- Code lf %>% mutate(a = 1, b = 2) %>% select(x) Output SELECT `x` FROM `df` # output is styled Code show_query(out, sql_options = sql_options(cte = TRUE)) Output WITH `q01` AS ( SELECT `x`, AVG(`y`) OVER (PARTITION BY `x`) AS `y`, `z` + 1.0 AS `z` FROM `df` ), `q02` AS ( SELECT `q01`.* FROM `q01` WHERE (`z` = 1.0) ) SELECT `LHS`.`x` AS `x`, `LHS`.`y` AS `y.x`, `LHS`.`z` AS `z.x`, `df`.`y` AS `y.y`, `df`.`z` AS `z.y` FROM `q02` AS `LHS` LEFT JOIN `df` ON (`LHS`.`x` = `df`.`x`)