Skip to content

Instantly share code, notes, and snippets.

@moodymudskipper
Created November 26, 2019 13:11
Show Gist options
  • Save moodymudskipper/0d2713c4f4561b9a1d42ced52ac4c90b to your computer and use it in GitHub Desktop.
Save moodymudskipper/0d2713c4f4561b9a1d42ced52ac4c90b to your computer and use it in GitHub Desktop.
dplyr functions by type of first input
``` r
# devtools::install_github("moodymudskipper/help")
library(help)
library(tidyverse, warn.conflicts = F)
env <- as.environment("package:dplyr")
dplyr_funs <- ls(envir = env)
arg_descr <- sapply(dplyr_funs, function(x) {
if(!is.function(get(x,envir = env))) return("not a function")
arg_nm <- names(formals(x,envir = env))[[1]]
if(!length(arg_nm)) return("no argument")
eval(substitute(doc(X, "dplyr")$arguments[[arg_nm]], list(X = x)))
})
# deprecated and reexported functions have no argument descriptions,
# they have a NULL value and are removed by `unlist`
arg_descr <- unlist(arg_descr)
enframe(arg_descr, "function","arg1") %>%
mutate(category = case_when(
grepl("^.n object", arg1) ~ "An object.",
grepl("^Variables", arg1) ~ "Variables",
grepl("predicate expression", arg1) ~ "A predicate expression.",
grepl("tbl", arg1) ~ "A `tbl` object.",
grepl("ata frames", arg1) ~ "Data frames.",
grepl("ata frame", arg1) ~ "A data frame.",
grepl("A sequence of two-sided formulas", arg1) ~ "A sequence of two-sided formulas",
grepl("A list of functions", arg1) ~ "A list of functions",
grepl("ectors", arg1) ~ "Vectors.",
grepl("ector", arg1) ~ "A vector.",
grepl("data source", arg1) ~ "A data source.",
grepl("data src", arg1) ~ "A data source.",
grepl("database connection", arg1) ~ "A database connection. ",
grepl("xpressions", arg1) ~ "Expressions",
grepl("xpression", arg1) ~ "Expression",
TRUE ~ gsub("(^.*?\\.).*","\\1", arg1)
)) %>%
select(`function`, category, arg1) %>%
mutate(arg1 = ifelse(nchar(arg1) > 50, paste0(substr(arg1,1,47),"..."), arg1)) %>%
as.data.frame() %>%
split(.$category) %>%
map(`[`,-2)
#> $`A `tbl` object.`
#> function arg1
#> 1 add_count a `tbl()` to tally/count.
#> 2 add_count_ a `tbl()` to tally/count.
#> 4 add_tally a `tbl()` to tally/count.
#> 5 add_tally_ a `tbl()` to tally/count.
#> 8 arrange A tbl. All main verbs are S3 generics and provi...
#> 10 arrange_all A `tbl` object.
#> 11 arrange_at A `tbl` object.
#> 12 arrange_if A `tbl` object.
#> 24 collapse A tbl
#> 25 collect A tbl
#> 27 compute A tbl
#> 29 count a `tbl()` to tally/count.
#> 30 count_ a `tbl()` to tally/count.
#> 56 distinct a tbl
#> 58 distinct_all A `tbl` object.
#> 59 distinct_at A `tbl` object.
#> 60 distinct_if A `tbl` object.
#> 61 do a tbl
#> 66 filter A tbl. All main verbs are S3 generics and provi...
#> 68 filter_all A `tbl` object.
#> 69 filter_at A `tbl` object.
#> 70 filter_if A `tbl` object.
#> 73 group_by a tbl
#> 75 group_by_all A `tbl` object.
#> 76 group_by_at A `tbl` object.
#> 78 group_by_if A `tbl` object.
#> 81 group_indices a tbl
#> 83 group_keys A tbl
#> 86 group_nest A tbl
#> 88 group_size a grouped tbl
#> 89 group_split A tbl
#> 91 group_vars A `tbl()`
#> 93 grouped_df a tbl or data frame.
#> 94 groups A `tbl()`
#> 105 make_tbl name of subclass. "tbl" is an abstract base cla...
#> 107 mutate A tbl. All main verbs are S3 generics and provi...
#> 109 mutate_all A `tbl` object.
#> 110 mutate_at A `tbl` object.
#> 111 mutate_if A `tbl` object.
#> 114 n_groups a grouped tbl
#> 127 rename A tbl. All main verbs are S3 generics and provi...
#> 129 rename_all A `tbl` object.
#> 130 rename_at A `tbl` object.
#> 131 rename_if A `tbl` object.
#> 136 sample_frac tbl of data.
#> 137 sample_n tbl of data.
#> 138 select A tbl. All main verbs are S3 generics and provi...
#> 140 select_all A `tbl` object.
#> 141 select_at A `tbl` object.
#> 142 select_if A `tbl` object.
#> 147 slice A tbl.
#> 159 src_local name of the function used to generate `tbl` obj...
#> 166 summarise A tbl. All main verbs are S3 generics and provi...
#> 168 summarise_all A `tbl` object.
#> 169 summarise_at A `tbl` object.
#> 170 summarise_if A `tbl` object.
#> 171 summarize A tbl. All main verbs are S3 generics and provi...
#> 173 summarize_all A `tbl` object.
#> 174 summarize_at A `tbl` object.
#> 175 summarize_if A `tbl` object.
#> 176 tally a `tbl()` to tally/count.
#> 177 tally_ a `tbl()` to tally/count.
#> 179 tbl_cube A named list of vectors. A dimension is a varia...
#> 181 tbl_nongroup_vars A tbl object
#> 182 tbl_vars A tbl object
#> 183 top_frac a `tbl()` to filter
#> 184 top_n a `tbl()` to filter
#> 185 transmute A tbl. All main verbs are S3 generics and provi...
#> 187 transmute_all A `tbl` object.
#> 188 transmute_at A `tbl` object.
#> 189 transmute_if A `tbl` object.
#> 190 ungroup A `tbl()`
#>
#> $`A data frame.`
#> function arg1
#> 3 add_rownames Input data frame with rownames.
#> 9 arrange_ A data frame.
#> 57 distinct_ A data frame.
#> 62 do_ A data frame.
#> 67 filter_ A data frame.
#> 74 group_by_ A data frame.
#> 77 group_by_drop_default A data frame
#> 82 group_indices_ A data frame.
#> 90 group_trim A grouped data frame
#> 104 location a data frame
#> 108 mutate_ A data frame.
#> 117 new_grouped_df A data frame
#> 128 rename_ A data frame.
#> 135 rowwise Input data frame.
#> 139 select_ A data frame.
#> 148 slice_ A data frame.
#> 167 summarise_ A data frame.
#> 172 summarize_ A data frame.
#> 180 tbl_df a data frame
#> 186 transmute_ A data frame.
#> 191 validate_grouped_df A data frame
#>
#> $`A data source.`
#> function arg1
#> 28 copy_to remote data source
#> 163 src_tbls a data src.
#> 178 tbl A data source
#>
#> $`A database connection. `
#> function arg1
#> 36 db_analyze A database connection.
#> 37 db_begin A database connection.
#> 38 db_commit A database connection.
#> 39 db_create_index A database connection.
#> 40 db_create_indexes A database connection.
#> 41 db_create_table A database connection.
#> 42 db_data_type A database connection.
#> 43 db_drop_table A database connection.
#> 44 db_explain A database connection.
#> 45 db_has_table A database connection.
#> 46 db_insert_into A database connection.
#> 47 db_list_tables A database connection.
#> 48 db_query_fields A database connection.
#> 49 db_query_rows A database connection.
#> 50 db_rollback A database connection.
#> 51 db_save_query A database connection.
#> 52 db_write_table A database connection.
#> 150 sql_escape_ident A database connection.
#> 151 sql_escape_string A database connection.
#> 152 sql_join A database connection.
#> 153 sql_select A database connection.
#> 154 sql_semi_join A database connection.
#> 155 sql_set_op A database connection.
#> 156 sql_subquery A database connection.
#> 157 sql_translate_env A database connection.
#>
#> $`A grouped tibble`
#> function arg1
#> 84 group_map A grouped tibble
#> 85 group_modify A grouped tibble
#> 92 group_walk A grouped tibble
#>
#> $`A list of functions`
#> function arg1
#> 72 funs A list of functions specified by: \n* Their name...
#>
#> $`A predicate expression.`
#> function arg1
#> 6 all_vars A predicate expression. This variable supports ...
#> 7 any_vars A predicate expression. This variable supports ...
#>
#> $`A sequence of two-sided formulas`
#> function arg1
#> 21 case_when A sequence of two-sided formulas. The left hand...
#>
#> $`A table of data`
#> function arg1
#> 123 pull A table of data
#>
#> $`a tibble`
#> function arg1
#> 80 group_data a tibble
#> 87 group_rows a tibble
#> 95 hybrid_call a tibble
#>
#> $`A vector.`
#> function arg1
#> 18 between A numeric vector of values
#> 31 cumall For `cumall()` and `cumany()`, a logical vector...
#> 32 cumany For `cumall()` and `cumany()`, a logical vector...
#> 33 cume_dist a vector of values to rank. Missing values are ...
#> 34 cummean For `cumall()` and `cumany()`, a logical vector...
#> 53 dense_rank a vector of values to rank. Missing values are ...
#> 54 desc vector to transform
#> 71 first A vector
#> 79 group_cols A character vector of variable names. When call...
#> 97 ident A character vector, or name-value pairs
#> 98 if_else Logical vector
#> 101 lag a vector of values
#> 102 last A vector
#> 103 lead a vector of values
#> 106 min_rank a vector of values to rank. Missing values are ...
#> 115 na_if Vector to modify
#> 118 nth A vector
#> 119 ntile a vector of values to rank. Missing values are ...
#> 120 order_by a vector to order_by
#> 121 percent_rank a vector of values to rank. Missing values are ...
#> 125 recode A vector to modify
#> 126 recode_factor A vector to modify
#> 132 rename_vars A character vector of existing column names.
#> 134 row_number a vector of values to rank. Missing values are ...
#> 143 select_var A character vector of existing column names.
#> 144 select_vars A character vector of existing column names.
#> 193 with_order vector to order by
#>
#> $`An object.`
#> function arg1
#> 13 as.tbl an object to coerce to a `tbl`
#> 14 as.tbl_cube an object to convert. Built in methods will con...
#> 64 explain An object to explain
#> 100 is.tbl an object to coerce to a `tbl`
#> 146 show_query An object to explain
#>
#> $`Data frames.`
#> function arg1
#> 19 bind_cols Data frames to combine. Each argument can eithe...
#> 20 bind_rows Data frames to combine. Each argument can eithe...
#> 124 rbind_list Data frames to combine. Each argument can eithe...
#>
#> $`Database name`
#> function arg1
#> 160 src_mysql Database name
#> 161 src_postgres Database name
#>
#> $`default value`
#> function arg1
#> 65 failwith default value
#>
#> $Expressions
#> function arg1
#> 35 current_vars Expressions to compute.
#>
#> $`list of variables`
#> function arg1
#> 96 id list of variables
#>
#> $`name of subclass.`
#> function arg1
#> 158 src name of subclass. "src" is an abstract base cla...
#>
#> $`no argument`
#> function arg1
#> 22 check_dbplyr no argument
#> 63 dr_dplyr no argument
#> 112 n no argument
#>
#> $`not a function`
#> function arg1
#> 15 band_instruments not a function
#> 16 band_instruments2 not a function
#> 17 band_members not a function
#> 116 nasa not a function
#> 164 starwars not a function
#> 165 storms not a function
#>
#> $`Object to show dimensions for.`
#> function arg1
#> 55 dim_desc Object to show dimensions for.
#>
#> $`object to test for "src"-ness.`
#> function arg1
#> 99 is.src object to test for "src"-ness.
#>
#> $`Path to SQLite database.`
#> function arg1
#> 162 src_sqlite Path to SQLite database. You can use the specia...
#>
#> $`Total number of items`
#> function arg1
#> 122 progress_estimated Total number of items
#>
#> $Variables
#> function arg1
#> 192 vars Variables to include/exclude in mutate/summaris...
#>
#> $`Various meanings depending on the verb.`
#> function arg1
#> 133 rename_vars_ Various meanings depending on the verb.
#> 145 select_vars_ Various meanings depending on the verb.
#>
#> $Vectors.
#> function arg1
#> 23 coalesce Vectors. All inputs should either be length 1, ...
#> 26 combine Vectors to combine.
#> 113 n_distinct vectors of values
#> 149 sql Character vectors that will be combined into a ...
```
<sup>Created on 2019-11-26 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)</sup>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment