Skip to content

Instantly share code, notes, and snippets.

@hadley
Created April 7, 2015 16:07
Show Gist options
  • Select an option

  • Save hadley/62ced301d8070642d268 to your computer and use it in GitHub Desktop.

Select an option

Save hadley/62ced301d8070642d268 to your computer and use it in GitHub Desktop.
data_sort <- function() {
desc <- FALSE;
my_sort <- function (data) {
sort(data, decreasing = desc)
}
attr(my_sort, "desc") <- function(x) {
desc <<- x
return(my_sort)
};
return(my_sort)
};
library(magrittr)
((data_sort() %>% attr("desc"))(TRUE))(1:10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment