Skip to content

Commit

Permalink
Tweak load.packages()
Browse files Browse the repository at this point in the history
Rename to `load_my_packages()`
  • Loading branch information
k5cents committed Nov 1, 2023
1 parent 9f9b674 commit 4398e27
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 55 deletions.
20 changes: 10 additions & 10 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: k5
Title: Kiernan Nicholls Miscellaneous
Version: 0.2.0
Version: 0.2.0.9001
Authors@R:
person("Kiernan", "Nicholls", , "[email protected]", role = c("aut", "cre"))
Description: Quality of life functions for interactive programming.
Expand All @@ -16,19 +16,18 @@ Depends:
R (>= 2.10)
Imports:
clipr (>= 0.8.0),
dplyr (>= 1.0.10),
fs (>= 1.5.2),
ggplot2 (>= 3.4.0),
dplyr (>= 1.1.3),
fs (>= 1.6.3),
ggplot2 (>= 3.4.4),
glue (>= 1.6.2),
lubridate (>= 1.9.0),
lubridate (>= 1.9.3),
magrittr (>= 2.0.3),
pacman (>= 0.5.1),
purrr (>= 1.0.1),
readr (>= 2.1.3),
purrr (>= 1.0.2),
readr (>= 2.1.4),
rlang (>= 1.1.1),
stringr (>= 1.5.0),
tibble (>= 3.1.8),
usethis (>= 2.1.6),
tibble (>= 3.2.1),
usethis (>= 2.2.2),
utils
Suggests:
covr (>= 3.6.1),
Expand All @@ -38,6 +37,7 @@ Suggests:
httr (>= 1.4.4),
janitor (>= 2.1.0),
knitr (>= 1.41),
pacman (>= 0.5.1),
readxl (>= 1.4.1),
rvest (>= 1.0.3),
scales (>= 1.2.1),
Expand Down
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export(file_age)
export(file_encoding)
export(filter_rx)
export(last_value)
export(load.packages)
export(load_my_packages)
export(na_in)
export(na_out)
export(na_rep)
Expand All @@ -26,8 +26,8 @@ export(read_csv_dumb)
export(read_delim_clip)
export(read_delim_dumb)
export(read_tsv_dumb)
export(save.packages)
export(save_last)
export(save_my_packages)
export(var_distinct)
export(var_missing)
export(view_firefox)
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# k5 0.2.0
# k5 (development version)

* Rename `load.packages()` to `load_my_packages()` and disable install.

# k5 0.1.0

Expand Down
21 changes: 11 additions & 10 deletions R/packages.R
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
#' Save and load packages from file
#'
#' @param path The path to a text file containing package names. If `NULL`
#' (default), then the default list is read from `k5/inst/PACKAGES`.
#' @param install If `TRUE`, install missing packages.
#' @param path The path to a text file containing one package per line. If
#' `NULL` (default), then the default list is read from `k5/inst/PACKAGES`.
#' @param x A character vector of package names to save. If `NULL` (default),
#' use all currently attached packages.
#' @return The list of packages, invisibly.
#' @export
load.packages <- function(path = NULL, install = FALSE) {
load_my_packages <- function(path = NULL) {
if (is.null(path)) {
path <- system.file("PACKAGES", package = "k5", mustWork = TRUE)
}
x <- readLines(path)
if (isFALSE(install)) {
x <- x[vapply(x, is_installed, logical(1))]
}
pacman::p_load(char = x)
is_loaded <- vapply(x, require_quiet, logical(1))
x <- x[is_loaded]
usethis::ui_done("load {length(x)} packages from {usethis::ui_path(path)}")
invisible(x)
}

#' @rdname load.packages
#' @rdname load_my_packages
#' @export
save.packages <- function(x = NULL, path = tempfile()) {
save_my_packages <- function(x = NULL, path = tempfile()) {
if (is.null(path)) {
path <- system.file("PACKAGES", package = "k5", mustWork = TRUE)
}
Expand All @@ -34,3 +31,7 @@ save.packages <- function(x = NULL, path = tempfile()) {
usethis::ui_done("saved {length(x)} packages to {usethis::ui_path(path)}")
invisible(x)
}

require_quiet <- function(...) {
suppressPackageStartupMessages(require(..., character.only = TRUE))
}
19 changes: 9 additions & 10 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ if (!interactive()) {
<!-- badges: start -->
[![Lifecycle: experimental][life_badge]][life_link]
[![CRAN status][cran_badge]][cran_link]
[![R build status][ga_badge]][ga_link]
![Downloads][dl_badge]
[![Codecov test coverage][cov_badge]][cov_link]
[![R build status][ga_badge]][ga_link]
<!-- badges: end -->

The goal of `k5` is to offer miscellaneous quality of life functions used by
The goal of 'k5' is to offer miscellaneous quality of life functions used by
[Kiernan Nicholls][kn] during interactive programming. They make things easier
for me but are _bad_ for scripts and packages.

## Installation

You can install the release version of `k5` from [CRAN][cran_link]:
You can install the release version of this package from [CRAN][cran_link]:

```{r install_cran, eval=FALSE}
install.packages("k5")
Expand All @@ -58,7 +59,7 @@ packageVersion("k5")
A list of frequently used packages can be loaded from a file.

```{r load}
load.packages(path = NULL, install = FALSE)
load_my_packages()
```

Some functions wrap common combos like `mean(x %in% y)` or `sum(is.na(x))`.
Expand Down Expand Up @@ -93,16 +94,14 @@ write_last()

<!-- refs: start -->
[life_badge]: https://img.shields.io/badge/lifecycle-experimental-orange.svg
[life_link]: https://lifecycle.r-lib.org/articles/stages.html
[life_link]: https://lifecycle.r-lib.org/articles/stages.html#experimental
[cran_badge]: https://www.r-pkg.org/badges/version/k5
[cran_link]: https://CRAN.R-project.org/package=k5
[ga_badge]: https://github.com/kiernann/k5/workflows/R-CMD-check/badge.svg
[ga_link]: https://github.com/kiernann/k5/actions
[cov_badge]: https://codecov.io/gh/kiernann/k5/branch/master/graph/badge.svg
[cov_link]: https://app.codecov.io/gh/kiernann/k5?branch=master
[ga_link]: https://github.com/kiernann/gluedown/actions
[cov_badge]: https://img.shields.io/codecov/c/github/kiernann/k5/master.svg
[cov_link]: https://app.codecov.io/gh/kiernann/k5?branch=master'
[dl_badge]: https://cranlogs.r-pkg.org/badges/grand-total/k5
[gh]: https://github.com/kiernann/k5
[kn]: https://github.com/kiernann
[zippr]: https://github.com/kiernann/zippr
[zip]: https://github.com/r-lib/zip
<!-- refs: end -->
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@
<!-- badges: start -->

[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html)
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![CRAN
status](https://www.r-pkg.org/badges/version/k5)](https://CRAN.R-project.org/package=k5)
[![R build
status](https://github.com/kiernann/k5/workflows/R-CMD-check/badge.svg)](https://github.com/kiernann/k5/actions)
![Downloads](https://cranlogs.r-pkg.org/badges/grand-total/k5)
[![Codecov test
coverage](https://codecov.io/gh/kiernann/k5/branch/master/graph/badge.svg)](https://app.codecov.io/gh/kiernann/k5?branch=master)
coverage](https://img.shields.io/codecov/c/github/kiernann/k5/master.svg)](https://app.codecov.io/gh/kiernann/k5?branch=master')
[![R build
status](https://github.com/kiernann/k5/workflows/R-CMD-check/badge.svg)](https://github.com/kiernann/gluedown/actions)
<!-- badges: end -->

The goal of `k5` is to offer miscellaneous quality of life functions
The goal of ‘k5’ is to offer miscellaneous quality of life functions
used by [Kiernan Nicholls](https://github.com/kiernann) during
interactive programming. They make things easier for me but are *bad*
for scripts and packages.

## Installation

You can install the release version of `k5` from
You can install the release version of this package from
[CRAN](https://CRAN.R-project.org/package=k5):

``` r
Expand All @@ -42,15 +43,15 @@ remotes::install_github("kiernann/k5")
``` r
library(k5)
packageVersion("k5")
#> [1] '0.0.5'
#> [1] '0.2.0'
```

A list of frequently used packages can be loaded from a file.

``` r
load.packages(path = NULL, install = FALSE)
#> ✔ load 21 packages from
#> '/home/kiernan/R/x86_64-pc-linux-gnu-library/4.2/k5/PACKAGES'
load_my_packages()
#> ✔ load 19 packages from
#> '/home/kiernan/R/x86_64-pc-linux-gnu-library/4.1/k5/PACKAGES'
```

Some functions wrap common combos like `mean(x %in% y)` or
Expand Down
16 changes: 7 additions & 9 deletions man/load.packages.Rd → man/load_my_packages.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tests/testthat/test-package.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
test_that("given packages can be saved", {
tmp <- tempfile()
a <- "test"
save.packages(a, tmp)
save_my_packages(a, tmp)
b <- readLines(tmp)
expect_equal(a, b)
})

test_that("attached packages can be saved", {
tmp <- tempfile()
save.packages(NULL, tmp)
save_my_packages(NULL, tmp)
expect_true(file.exists(tmp))
b <- readLines(tmp)
expect_gt(length(b), 1)
Expand All @@ -17,6 +17,6 @@ test_that("attached packages can be saved", {
test_that("default packages can be loaded", {
tmp <- tempfile()
writeLines("k5", tmp)
x <- load.packages(path = tmp, install = FALSE)
x <- load_my_packages(path = tmp)
expect_length(x, 1)
})

0 comments on commit 4398e27

Please sign in to comment.