Skip to content

Instantly share code, notes, and snippets.

@klmr
Last active December 20, 2015 15:09
Show Gist options
  • Save klmr/6152098 to your computer and use it in GitHub Desktop.
Save klmr/6152098 to your computer and use it in GitHub Desktop.
When not to use point-free style: Composed functions don’t always auto-vectorise well. As a consequence, we’re left with monsters such as this one. It might be worth investigating whether the function composition tools could be changed (transparently) to make auto-vectorisation more universal. In particular, the problem lies with `fapply`, which…
capitalize <-
p(fapply, toupper %.% p(substring, 1, 1), p(substring, 2)) %|>%
p(lapply, p(paste, collapse = '')) %|>% unlist
# versus
capitalize <- function (str) paste(toupper(substring(str, 1, 1)),
substring(str, 2), sep = '')
# Usage (in both cases):
capitalize(c('abc', 'def')) # => 'Abc' 'Def'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment