Skip to contents

progutils contains utility functions, for example to reorder values, check equality, construct messages, or handle files and directories.

Installation

Visit the progutils website to explore the package, or install progutils from GitHub using the following R code (you need to run R as administrator):

if(!requireNamespace("remotes", quietly = TRUE)) {
  install.packages(pkgs = "remotes", quiet = FALSE)
}
remotes::install_github(repo = "JesseAlderliesten/progutils",
                        dependencies = NA, upgrade = FALSE, force = FALSE,
                        quiet = FALSE, build_vignettes = TRUE, lib = NULL,
                        verbose = getOption("verbose"))

For more information about installing and configuring R and RStudio, see my package checkrpkgs.

Examples

Every once in a while, reading data into R results in a factor that should be converted to a numeric vector. The code below illustrates that using as.numeric(x) from base R does not work to achieve this while using as.numeric_safe() from progutils does work.

library(progutils)
x <- factor(11:13)
x
#> [1] 11 12 13
#> Levels: 11 12 13
as.numeric(x) # Returns the indices instead of the values!
#> [1] 1 2 3
as.numeric_safe(x) # Returns the values.
#> [1] 11 12 13

Similarly, using relevel() or levels() from base R to reorder factor levels does not work, whereas using reorder_levels() from progutils does:

library(progutils)
f_orig <- factor(letters[c(12:13, 13:11)], levels = letters[13:11])
f_orig
#> [1] l m m l k
#> Levels: m l k

f_test <- f_orig
levels(f_test) <- letters[11:13]
f_test # Also changes the values!
#> [1] l k k l m
#> Levels: k l m
reorder_levels(x = f_orig, new_order = letters[11:13]) # Only changes the levels
#> [1] l m m l k
#> Levels: k l m

To use a named numeric vector in the subtitle of a plot, it should be converted to a character string wrapped to an appropriate length, to prevent text from running off the plot. progutils provides a way to achieve that by combining vect_to_char() and wrap_text():

library(progutils)
msg_part_one <- "Some\nmessage you want to display"
num_vect <- c(j = 10, k = 11, l = 12)

cat(wrap_text(paste(msg_part_one, vect_to_char(num_vect)), width = 20))
#> Some message you
#> want to display j:
#> 10, k: 11, l: 12

# Retaining newlines that were present in the original message:
cat(wrap_text(paste(msg_part_one, vect_to_char(num_vect)), width = 20,
              ignore_newlines = FALSE))
#> Some
#> message you want to
#> display j: 10, k:
#> 11, l: 12

License

This project is licensed under the terms of the MIT License.

Citation

To cite package 'progutils' in publications use:

  Alderliesten J (2026). _progutils: Programming Utilities_. R package
  version 0.13.0, <https://github.com/JesseAlderliesten/progutils>.

A BibTeX entry for LaTeX users is

  @Manual{,
    title = {progutils: Programming Utilities},
    author = {Jesse Alderliesten},
    year = {2026},
    note = {R package version 0.13.0},
    url = {https://github.com/JesseAlderliesten/progutils},
  }

Similar packages

Many packages with miscellaneous functions exist on GitHub and CRAN: frequently they have ‘misc’ or ‘util’ in their title or description. In addition, many packages have an utils folder in their R directory.