Commit 8cef897d authored by Holger Brandl's avatar Holger Brandl

added `as` and import `splat`

parent 7c683a35
......@@ -133,6 +133,19 @@ frame_data = function(...) tibble::tribble(...)
add_rownames = function(...) tibble::rownames_to_column(...)
## redefine dply::splat to allow for more streamlined rowwise df-processing
## see https://groups.google.com/forum/?utm_source=digest&utm_medium=email#!topic/manipulatr/E6WOcHlRJcw
#splat = function (flat) {
# function(args, ...) {
# do.call(flat, c(args, list(...)))
# }
#}
## for now simply import just splat from plyr namespace
install_package("plyr")
splat = plyr::splat
########################################################################################################################
#### data.frame manipulation
......@@ -197,13 +210,13 @@ set_names <- function(df, ...){
rify_names <- function(df){
warning("DEPRECATED: use pretty_columns instead");
names(df) <- names(df) %>% str_replace_all(c(" "="_", "-"="_"));
names(df) <- names(df) %>% str_replace_all(c(" "="_", "-"="_", "/"="_"));
df
}
pretty_columns <- function(df){
names(df) <- names(df) %>%
str_replace_all("[#=.() -]+", "_") %>%
str_replace_all("[#=.()/ -]+", "_") %>%
str_replace("[_]+$", "") %>%
str_replace("^[_]+", "") %>%
tolower;
......@@ -297,6 +310,12 @@ filter_count <- function(df, ...){
filter(df, ...)
}
# Example: publications %>% count(journal) %>% as("num_pubs")
as = function(df, name){
names(df)[length(names(df))] = name
df
}
distinct_all = function (x, ...) distinct(x, ..., .keep_all=T)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment