Created
February 20, 2019 19:22
-
-
Save cosi1/6dddde8ccc465933784c2e4ee25dd831 to your computer and use it in GitHub Desktop.
Range matching in R
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
| range_if = function(.., ..., default = NULL) { | |
| for (expr in list(...)) { | |
| s = substitute(expr) | |
| if (length(s) < 3 || s[[1]] != as.symbol("~")) { | |
| stop("Invalid argument. Use `condition ~ expression`") | |
| } | |
| if (isTRUE(eval(s[[2]]))) return(eval(s[[3]])) | |
| } | |
| default | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment