Title: | Execute Expensive Operations Only Once |
---|---|
Description: | Allows you to easily execute expensive compute operations only once, and save the resulting object to disk. |
Authors: | Gordon McDonald [aut, cre] |
Maintainer: | Gordon McDonald <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.4.1 |
Built: | 2025-02-18 03:55:03 UTC |
Source: | https://github.com/gdmcdonald/once |
The once()
function allows you to easily execute expensive compute operations only once, and save the resulting object to disk.
once(expr, file_path = NULL, rerun = FALSE)
once(expr, file_path = NULL, rerun = FALSE)
expr |
The expensive expression to evaluate |
file_path |
File path for saving the output object as an Rds file. Note that if no file name is provided it will not save! |
rerun |
Rerun the expression anyway and save the result? Defaults to false. |
the results of expr
save_file <- tempfile(fileext = ".Rds") # temporary file path - replace with your preferred saved file path my_out <- runif(1e8) %>% # some expensive operation mean() %>% once(file_path = save_file) # only do it once, save output to this file.
save_file <- tempfile(fileext = ".Rds") # temporary file path - replace with your preferred saved file path my_out <- runif(1e8) %>% # some expensive operation mean() %>% once(file_path = save_file) # only do it once, save output to this file.