Data Science Desktop Survival Guide
by Graham Williams |
|||||
Assignment |
20200105
Preferred
a <- 42
b <- mean(x) Discouraged |
a = 42
b = mean(x)
The forward assignment base::- should generally be avoided. A single use case justifies it in pipelines where logically we do an assignment at the end of a long sequence of operations. As a side effect operator it is vitally important to highlight the assigned variable whenever possible and so out-denting the variable after the forward assignment to highlight it is recommended. Preferred |
ds[vars] %>%
sapply(function(x) all(x == x[1L])) %>% which() %>% names() %T>% print() -> constants Traditional |
constants <-
ds[vars] %>% sapply(function(x) all(x == x[1L])) %>% which() %>% names() %T>% print() Discouraged |
ds[vars] %>%
sapply(function(x) all(x == x[1L])) %>% which() %>% names() %T>% print() -> constants
|