Learn R Programming

onetime

Listen very carefully. I shall say this only once.

Michelle Dubois, ’Allo ’Allo

The onetime package provides convenience functions to run R code only once (ever) per user. For example, you can:

  • Show a startup message only the first time (ever) that a package is loaded.
  • Run cleanup code just once after an upgrade.
  • Show the user a message, with the option not to show it again.

Onetime is a lightweight package. It requires just two package dependencies, rappdirs and filelock, with no further indirect dependencies. The total size including these dependencies is less than 50 Kb.

Example

library(onetime)

ids  <- paste0("onetime-readme-", 1:3) 

for (i in 1:5) {
  onetime_do(cat("This command will only be run once.\n"), id = ids[1])
  onetime_warning("This warning will only be shown once.", id = ids[2])
  onetime_message("This message will only be shown once.", id = ids[3])
}
#> This command will only be run once.
#> Warning: This warning will only be shown once.
#> This message will only be shown once.

Installation

Install onetime from r-universe:

install.packages("onetime", repos = c("https://hughjonesd.r-universe.dev", 
                                      "https://cloud.r-project.org"))

Or on CRAN:

install.packages("onetime")

Or install the development version from github with:

# install.packages("remotes")
remotes::install_github("hughjonesd/onetime")

Copy Link

Version

Install

install.packages('onetime')

Monthly Downloads

187

Version

0.2.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

David Hugh-Jones

Last Published

September 3rd, 2023

Functions in onetime (0.2.0)

onetime

Run code only once
onetime_mark_as_done

Mark an action as done
onetime_only

Wrap a function to be called only once
onetime_do

Run code only once
onetime_been_done

Check if a onetime call has already been made
onetime_message_confirm

Print a message, and ask for confirmation to hide it in future
onetime_dir

Return a path to a directory beneath the onetime base directory
onetime_reset

Reset a onetime call by ID
onetime-rlang

Print a warning or message only once using rlang functions
onetime_warning

Print a warning or message only once
set_ok_to_store

Grant or revoke permission to store lockfiles on the user's computer
check_ok_to_store

Check if the package has permission to store files on the user's computer