1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
# frame is checked
Code
translate_sql(sum(x, na.rm = TRUE), vars_frame = c(1, 0))
Condition
Warning:
Windowed expression `SUM(`x`)` does not have explicit order.
i Please use `arrange()` or `window_order()` to make deterministic.
Error in `rows()`:
! `from` (1) must be less than `to` (0)
# window_frame()
Code
lf %>% window_frame(-3, 0) %>% window_order(x) %>% mutate(z = sum(y, na.rm = TRUE)) %>%
show_query()
Output
<SQL>
SELECT *, SUM(`y`) OVER (ORDER BY `x` ROWS 3 PRECEDING) AS `z`
FROM `df`
---
Code
lf %>% window_frame(-3) %>% window_order(x) %>% mutate(z = sum(y, na.rm = TRUE)) %>%
show_query()
Output
<SQL>
SELECT
*,
SUM(`y`) OVER (ORDER BY `x` ROWS BETWEEN 3 PRECEDING AND UNBOUNDED FOLLOWING) AS `z`
FROM `df`
# window_frame() checks arguments
Code
window_frame(lf, "a")
Condition
Error in `window_frame()`:
! is.numeric(from) is not TRUE
---
Code
window_frame(lf, 1:2)
Condition
Error in `window_frame()`:
! length(from) == 1 is not TRUE
---
Code
window_frame(lf, 1, "a")
Condition
Error in `window_frame()`:
! is.numeric(to) is not TRUE
---
Code
window_frame(lf, 1, 1:2)
Condition
Error in `window_frame()`:
! length(to) == 1 is not TRUE
|