Last active
August 29, 2015 14:25
-
-
Save dholstius/228b87672155c2335578 to your computer and use it in GitHub Desktop.
Unexpected result of currying substr()
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
extract_substrings <- function (x, ...) { | |
make_extractor <- function (i) { | |
#message(min(i), " to ", max(i)) | |
function (s) substr(s, min(i), max(i)) | |
} | |
extractors <- lapply(list(...), make_extractor) | |
lapply(extractors, function (f) f(x)) | |
} | |
ALPHABET <- paste0(LETTERS, collapse = "") | |
extract_substrings(rep(ALPHABET, times = 5), 1:4, 6:8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why do I see different behavior when
message
is (un)commented?