These are methods for the dplyr mutate() and transmute() generics. They are translated to computed expressions in the SELECT clause of the SQL query.

# S3 method for tbl_lazy
mutate(.data, ...)

Arguments

.data

A lazy data frame backed by a database query.

...

<data-masking> Variables, or functions or variables. Use desc() to sort a variable in descending order.

Value

Another tbl_lazy. Use show_query() to see the generated query, and use collect() to execute the query and return data to R.

Examples

library(dplyr, warn.conflicts = FALSE) db <- memdb_frame(x = 1:5, y = 5:1) db %>% mutate(a = (x + y) / 2, b = sqrt(x^2L + y^2L)) %>% show_query()
#> <SQL> #> SELECT `x`, `y`, (`x` + `y`) / 2.0 AS `a`, SQRT(POWER(`x`, 2) + POWER(`y`, 2)) AS `b` #> FROM `dbplyr_015`
# dbplyr automatically creates subqueries as needed db %>% mutate(x1 = x + 1, x2 = x1 * 2) %>% show_query()
#> <SQL> #> SELECT `x`, `y`, `x1`, `x1` * 2.0 AS `x2` #> FROM (SELECT `x`, `y`, `x` + 1.0 AS `x1` #> FROM `dbplyr_015`)