Last active
October 22, 2017 18:28
-
-
Save hadley/7572036 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
frame <- function(from = -Inf, to = 0) { | |
if (from >= to) stop("from must be less than to", call. = FALSE) | |
dir <- function(x) if (x < 0) "PRECEDING" else "FOLLOWING" | |
val <- function(x) if (is.finite(x)) as.integer(x) else "UNBOUNDED" | |
bound <- function(x) { | |
if (x == 0) return("CURRENT ROW") | |
paste(val(x), dir(x)) | |
} | |
if (to == 0) { | |
bound(from) | |
} else { | |
paste0("BETWEEN ", bound(from), " AND ", bound(to)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in JS just for fun: