knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

devtools::load_all()

jpw

Personal R package to house miscellaneous tidbits of code.

Installation

You can install the development version of jpw from GitHub with:

install.packages("devtools")
devtools::install_github("WhiteJP/jpw")

And load it:

library(jpw)

Examples

Below are some examples of functions in jpw.

Simple statistical calcluations

censor_left(1:10, min = 5)
censor_right(1:10, max = 5)
censor_both(1:10, min = 3, max = 7)
normalise(1:10) # min = 0 max = 1
scale_minmax(1:10, out_min = -100, out_max = 100) # min = `mn`, max = `mx`

Other

vec2prose(c("Peanut", "Butter", "Jelly"), oxford_comma = FALSE)
x <- c(1,  2, 3, NA,  5, NA, 7,  8, NA, 10)
y <- c(NA, 9, 8,  7,  5, NA, 4,  3,  2,  1)

na2na(x > 8 | x == y)
extract_nums_tgthr(c("sdff234", "12aaa34"))
extract_nums_all(c("12aaa34", "-12.4 54.3", "adfsdf.344 -1.2 4"))
remove_nums(c("12aaa34",  "adfsdf.344 -1.2 4"), trimws = TRUE)
int2bin(c(12, 5, NA, 90342))
x <- c(100010, 234,  1, 34)
add_zeros(x) # default to longest nchar in vector
add_zeros(x, len = 9) # can stipulate longer
add_by_position(LETTERS[1:6], "NEW", 5)
rev_diag(3)
rev_diag(6, x = 12)
brackets(123)
brackets("foo", type = "square")
where(sum)
where("sd")


WhiteJP/jpw documentation built on April 17, 2025, 5:47 a.m.