-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
90 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
Package: ksmisc | ||
Type: Package | ||
Title: What the Package Does (Title Case) | ||
Version: 0.1.0 | ||
Author: Who wrote it | ||
Maintainer: The package maintainer <yourself@somewhere.net> | ||
Description: More about what it does (maybe more than one line) | ||
Use four spaces when indenting paragraphs within the Description. | ||
License: What license is it under? | ||
Title: Utility Function for Kevin Stachelek | ||
Version: 0.0.0.9000 | ||
Authors@R: | ||
person(given = "Kevin", | ||
family = "Stachelek", | ||
role = c("aut", "cre"), | ||
email = "kstachelek@protonmail.com", | ||
comment = c(ORCID = "0000-0003-2085-695X")) | ||
Description: What the package does (one paragraph). | ||
License: MIT + file LICENSE | ||
Encoding: UTF-8 | ||
LazyData: true | ||
RoxygenNote: 7.0.2 | ||
Roxygen: list(markdown = TRUE) | ||
Imports: | ||
magrittr, | ||
dplyr, | ||
rtweet | ||
RoxygenNote: 7.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
exportPattern("^[[:alpha:]]+") | ||
importFrom(magrittr,"%>%") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#' Transmute Pairwise | ||
#' | ||
#' return a dataframe consisting of all combinations of arbitrary pairwise operations across a selection of columns | ||
#' | ||
#' @param df | ||
#' @param fun | ||
#' @param ... | ||
#' @param associative | ||
#' | ||
#' @return | ||
#' @export | ||
#' | ||
#' @examples mpg %>% | ||
#' select(where(is.numeric)) %>% | ||
#' mutate(select(cur_data(), c(displ, cty, hwy)) %>% | ||
#' transmute_pairwise(`/`, associative = FALSE) %>% | ||
#' rename_with(~paste0(.x, "_ratio")) %>% | ||
#' identity() | ||
#' ) | ||
transmute_pairwise <- function(df, fun, ..., associative = TRUE){ | ||
|
||
transmute2 <- function(df, .x, .y, fun, ...){ | ||
|
||
dplyr::transmute(df, "{{ .x }}_{{ .y }}" := fun({{ .x }}, {{ .y }}, ...)) | ||
} | ||
|
||
var_pairs <- t(combn(names(df), 2)) %>% | ||
tibble::as_tibble() %>% | ||
setNames(c(".x", ".y")) | ||
|
||
if(!associative){ | ||
var_pairs <- dplyr::bind_rows( | ||
var_pairs, | ||
rename(var_pairs, .y = .x, .x = .y) | ||
) | ||
} | ||
|
||
dplyr::mutate(var_pairs, dplyr::across(dplyr::everything(), syms)) %>% | ||
purrr::pmap_dfc(transmute2, df = df, fun = fun, ...) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.