Learn R Programming

⚠️There's a newer version (0.2.1) of this package.Take me there.

k5

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.

Installation

You can install the development version of k5 from GitHub:

# install.packages("remotes")
remotes::install_github("kiernann/k5")

Example

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)).

x <- c("VT", "NH", "ZZ", "ME", NA)
prop_in(x, state.abb)
#> [1] 0.75
count_na(x)
#> [1] 1

Some functions wrap functions from other packages with different defaults.

dplyr::count(mtcars, cyl)
#>   cyl  n
#> 1   4 11
#> 2   6  7
#> 3   8 14

# sort and add fraction
k5::count2(mtcars, cyl)
#> # 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.

df <- tail(mtcars, 50)
write_last()
#> ℹ `.Last.value` has class 'data.frame'
#> ✓ Saved tab-separated file '/tmp/RtmpFTaCH6/file15127cc7851b.tsv' (1.25K)
vc <- sample(state.name, 1000, replace = TRUE)
write_last()
#> ℹ `.Last.value` has class 'character'
#> ✓ Saved line-separated file '/tmp/RtmpFTaCH6/file151235b67c89.txt' (9.19K)

Copy Link

Version

Install

install.packages('k5')

Monthly Downloads

218

Version

0.0.5

License

GPL-3

Issues

Pull Requests

Stars

Forks

Last Published

January 24th, 2023

Functions in k5 (0.0.5)

copy_last

Copy the last object to the clipboard
na_out

Remove out
load.packages

Save and load packages from file
file_encoding

File Encoding
na_in

Remove in
file_age

File modification date age
count_out

Count out
count2

Count the way you want
what_in

Which in
prop_na

Proportion missing
prop_out

Proportion out
gaa

GAA Team Abbreviations by Season and Team ID
filter_rx

Filter a data frame by a regular expression
what_out

Which out
%out%

Inverted match
word_count

Count file words, lines, and bytes
%>%

Pipe operator
print_all

Print all rows of elements
view_last

View the last object
view_firefox

View an HTML document in Firefox
last_value

Return the last value
write_delim_clip

Write a table from the clipboard
na_rep

Remove repeated character elements
read_delim_clip

Read a table from the clipboard
prop_distinct

Proportion missing
prop_in

Proportion in
write_last

Write the last value to disk
read_delim_dumb

Read a text file without column guessing
count_in

Count in
contract_convert

Convert contract names to factor intervals
count_diff

Count set difference
aws_info

List all objects in an AWS bucket
count_na

Count missing