Title: | Tools for Working with Names |
---|---|
Description: | A system for organizing column names in data. Aimed at supporting a prefix-based and suffix-based column naming scheme. Extends 'dplyr' functionality to add ordering by function and more explicit renaming. |
Authors: | Christopher T. Kenny [aut, cre] |
Maintainer: | Christopher T. Kenny <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.1 |
Built: | 2024-11-19 05:56:17 UTC |
Source: | https://github.com/christopherkenny/name |
Add Prefix
add_pref(x, pref)
add_pref(x, pref)
x |
character; string to change |
pref |
character; prefix to add |
character
x <- c('pop', 'pop_2020_est', 'pop_white_2020', 'pop_black_2020') add_pref(x, 'census_')
x <- c('pop', 'pop_2020_est', 'pop_white_2020', 'pop_black_2020') add_pref(x, 'census_')
Add Suffix
add_suff(x, suff)
add_suff(x, suff)
x |
character; string to change |
suff |
character; suffix to add |
character
x <- c('pop', 'pop_2020_est', 'pop_white_2020', 'pop_black_2020') add_suff(x, '_cen')
x <- c('pop', 'pop_2020_est', 'pop_white_2020', 'pop_black_2020') add_suff(x, '_cen')
Compare the Names of Two Objects
compare_names(x, y)
compare_names(x, y)
x |
first object |
y |
second object |
character vector of differences, invisibly
s <- tibble::tibble(a = 1, b = 2, d = 3) t <- tibble::tibble(a = 1, d = 3, c = 2) compare_names(s, t)
s <- tibble::tibble(a = 1, b = 2, d = 3) t <- tibble::tibble(a = 1, d = 3, c = 2) compare_names(s, t)
List Phrases
list_phrase(tb, loc = 2)
list_phrase(tb, loc = 2)
tb |
tibble; data to list prefixes in |
loc |
number of location to list. For example |
character
tb <- tibble::tibble(pop = 10, pop_2020_est = 9, pop_white_2020 = 8, pop_black_2020 = 2) list_phrase(tb)
tb <- tibble::tibble(pop = 10, pop_2020_est = 9, pop_white_2020 = 8, pop_black_2020 = 2) list_phrase(tb)
List Prefixes
list_pref(tb)
list_pref(tb)
tb |
tibble; data to list prefixes in |
character
tb <- tibble::tibble(pop = 10, pop_2020_est = 9, pop_white_2020 = 8, pop_black_2020 = 2) list_pref(tb)
tb <- tibble::tibble(pop = 10, pop_2020_est = 9, pop_white_2020 = 8, pop_black_2020 = 2) list_pref(tb)
List Suffixes
list_suff(tb)
list_suff(tb)
tb |
tibble; data to list prefixes in |
character
tb <- tibble::tibble(pop = 10, pop_2020_est = 9, pop_white_2020 = 8, pop_black_2020 = 2) list_suff(tb)
tb <- tibble::tibble(pop = 10, pop_2020_est = 9, pop_white_2020 = 8, pop_black_2020 = 2) list_suff(tb)
Relocate columns
relocate_with( .data, .fn, .cols = everything(), .before = NULL, .after = NULL, ... )
relocate_with( .data, .fn, .cols = everything(), .before = NULL, .after = NULL, ... )
.data |
A |
.fn |
A function to reorder |
.cols |
Columns to move |
.before , .after
|
Destination of columns. If both selected, errors. If neither, moves to right of first selected column. |
... |
additional arguments to pass to |
And object with same type as .data
.
data(sd) sd |> relocate_with(sort)
data(sd) sd |> relocate_with(sort)
Remove Phrase
rem_phrase(x, phrase)
rem_phrase(x, phrase)
x |
character; string to change |
phrase |
character; phrase to remove |
character
x <- c('pop', 'pop_2020_est', 'pop_white_2020', 'pop_black_2020') rem_phrase(x, '_2020')
x <- c('pop', 'pop_2020_est', 'pop_white_2020', 'pop_black_2020') rem_phrase(x, '_2020')
Remove Prefix
rem_pref(x, pref)
rem_pref(x, pref)
x |
character; string to change |
pref |
character; prefix to remove |
character
x <- c('pop', 'pop_2020_est', 'pop_white_2020', 'pop_black_2020') rem_pref(x, 'pop_')
x <- c('pop', 'pop_2020_est', 'pop_white_2020', 'pop_black_2020') rem_pref(x, 'pop_')
Remove Suffix
rem_suff(x, suff)
rem_suff(x, suff)
x |
character; string to change |
suff |
character; suffix to remove |
character
x <- c('pop', 'pop_2020_est', 'pop_white_2020', 'pop_black_2020') rem_suff(x, '_2020')
x <- c('pop', 'pop_2020_est', 'pop_white_2020', 'pop_black_2020') rem_suff(x, '_2020')
Rename with, but Loudly
rename_with_loud(.data, .fn, .cols = everything(), ...)
rename_with_loud(.data, .fn, .cols = everything(), ...)
.data |
A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr). See Methods, below, for more details. |
.fn |
A function used to transform the selected |
.cols |
< |
... |
For For |
.data renamed
tb <- tibble::tibble(pop = 10, pop_2020_est = 9, pop_white_2020 = 8, pop_black_2020 = 2) rename_with_loud(tb, \(x) rem_suff(x, '_2020'))
tb <- tibble::tibble(pop = 10, pop_2020_est = 9, pop_white_2020 = 8, pop_black_2020 = 2) rename_with_loud(tb, \(x) rem_suff(x, '_2020'))
Replace Phrase
repl_phrase(x, phrase, repl)
repl_phrase(x, phrase, repl)
x |
character; string to change |
phrase |
character; phrase to replace |
repl |
character; phrase to replace with |
character
x <- c('pop', 'pop_2020_est', 'pop_white_2020', 'pop_black_2020') repl_phrase(x, '_2020', '_20')
x <- c('pop', 'pop_2020_est', 'pop_white_2020', 'pop_black_2020') repl_phrase(x, '_2020', '_20')
Replace Prefix
repl_pref(x, pref, repl)
repl_pref(x, pref, repl)
x |
character; string to change |
pref |
character; prefix to replace |
repl |
character; prefix to replace with |
character
x <- c('pop', 'pop_2020_est', 'pop_white_2020', 'pop_black_2020') repl_pref(x, 'pop_', 'p_')
x <- c('pop', 'pop_2020_est', 'pop_white_2020', 'pop_black_2020') repl_pref(x, 'pop_', 'p_')
Replace Suffix
repl_suff(x, suff, repl)
repl_suff(x, suff, repl)
x |
character; string to change |
suff |
character; suffix to replace |
repl |
character; suffix to replace with |
character
x <- c('pop', 'pop_2020_est', 'pop_white_2020', 'pop_black_2020') repl_suff(x, '_2020', '_20')
x <- c('pop', 'pop_2020_est', 'pop_white_2020', 'pop_black_2020') repl_suff(x, '_2020', '_20')
This data set contains demographic and election information for South Dakota
data("sd")
data("sd")
Voting and Election Science Team, 2020, "2020 Precinct-Level Election Results", https://doi.org/10.7910/DVN/K7760H, Harvard Dataverse, V23
Voting and Election Science Team, 2018, "2016 Precinct-Level Election Results", https://doi.org/10.7910/DVN/NH5S2I, Harvard Dataverse, V71
Voting and Election Science Team, 2019, "2018 Precinct-Level Election Results", https://doi.org/10.7910/DVN/UBKYRU, Harvard Dataverse, V48
Kenny & McCartan (2021, Aug. 10). ALARM Project: 2020 Redistricting Data Files. Retrieved from https://github.com/alarm-redist/census-2020/
data(sd)
data(sd)
Sort by Phrase
sort_phrase(x, loc = 2)
sort_phrase(x, loc = 2)
x |
character; strings to sort |
loc |
number of location to sort by. For example |
character
x <- c('pop_2020_est', 'pop_white_2020', 'pop_black_2020', 'pop_white_2021') sort_phrase(x)
x <- c('pop_2020_est', 'pop_white_2020', 'pop_black_2020', 'pop_white_2021') sort_phrase(x)
Sort by Prefix
sort_pref(x)
sort_pref(x)
x |
character; strings to sort |
character
x <- c('pop', 'pop_2020_est', 'pop_white_2020', 'pop_black_2020') sort_pref(x)
x <- c('pop', 'pop_2020_est', 'pop_white_2020', 'pop_black_2020') sort_pref(x)
Sort by Suffix
sort_suff(x)
sort_suff(x)
x |
character; strings to sort |
character
x <- c('pop_2020_est', 'pop_white_2020', 'pop_black_2020', 'pop_white_2021') sort_suff(x)
x <- c('pop_2020_est', 'pop_white_2020', 'pop_black_2020', 'pop_white_2021') sort_suff(x)