This file contains hidden or 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
| sliding_window <- function(x, # numeric vector | |
| width, # window size | |
| callback=mean, # summary function to return a single value | |
| fill=FALSE) { # make output as long as input? Set TRUE for adding data.frame columns | |
| x_length <- length(x) | |
| stopifnot(x_length > width) # check if this is appropriate | |
| starts <- seq_len(x_length - width) # start points | |
| ends <- starts + width # end points |
This file contains hidden or 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
| `%except%` <- function (try.expression, catch.expression) { | |
| tryCatch(try.expression, | |
| error=function(e) { | |
| if ( inherits(catch.expression, 'function') ) { | |
| catch.expression(e) | |
| } else { | |
| catch.expression | |
| } | |
| }) |