The goal of k5
is to offer miscellaneous quality of life
functions used by Kiernan
Nicholls during interactive programming. They make things easier for
me but are bad for scripts and packages.
You can install the development version of k5
from GitHub:
# install.packages("remotes")
::install_github("kiernann/k5") remotes
library(k5)
packageVersion("k5")
#> [1] '0.0.4'
A list of frequently used packages can be loaded from a file.
load.packages(path = NULL, install = FALSE)
#> ✔ load 21 packages from
#> '/home/kiernan/R/x86_64-pc-linux-gnu-library/4.2/k5/PACKAGES'
Some functions wrap common combos like mean(x %in% y)
or
sum(is.na(x))
.
<- c("VT", "NH", "ZZ", "ME", NA)
x prop_in(x, state.abb)
#> [1] 0.75
count_na(x)
#> [1] 1
Some functions wrap functions from other packages with different defaults.
::count(mtcars, cyl)
dplyr#> cyl n
#> 1 4 11
#> 2 6 7
#> 3 8 14
# sort and add fraction
::count2(mtcars, cyl)
k5#> # A tibble: 3 × 3
#> cyl n p
#> <dbl> <int> <dbl>
#> 1 8 14 0.438
#> 2 4 11 0.344
#> 3 6 7 0.219
There are also some handy shortcuts for the .Last.value
tool.
<- tail(mtcars, 50)
df write_last()
#> ℹ `.Last.value` has class 'data.frame'
#> ✓ Saved tab-separated file '/tmp/RtmpFTaCH6/file15127cc7851b.tsv' (1.25K)
<- sample(state.name, 1000, replace = TRUE)
vc write_last()
#> ℹ `.Last.value` has class 'character'
#> ✓ Saved line-separated file '/tmp/RtmpFTaCH6/file151235b67c89.txt' (9.19K)