Skip to content

Instantly share code, notes, and snippets.

@dholstius
Last active August 29, 2015 14:25
Show Gist options
  • Save dholstius/228b87672155c2335578 to your computer and use it in GitHub Desktop.
Save dholstius/228b87672155c2335578 to your computer and use it in GitHub Desktop.
Unexpected result of currying substr()
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)
@dholstius
Copy link
Author

Why do I see different behavior when message is (un)commented?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment