Title: | Run Once and Save Result |
Version: | 0.2.3 |
Description: | Package 'runonce' helps automating the saving of long-running code to help running the same code multiple times. If you run some long-running code once, it saves the result in a file on disk. Then, if the result already exists, i.e. if the code has already been run and its output has already been saved, it just reads the result from the stored file instead of running the code again. |
License: | GPL-3 |
Encoding: | UTF-8 |
RoxygenNote: | 7.1.1 |
Imports: | bigassertr, urltools |
Suggests: | testthat (≥ 2.1.0), covr |
URL: | https://github.com/privefl/runonce |
BugReports: | https://github.com/privefl/runonce/issues |
NeedsCompilation: | no |
Packaged: | 2021-10-02 08:22:15 UTC; au639593 |
Author: | Florian Privé [aut, cre] |
Maintainer: | Florian Privé <florian.prive.21@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2021-10-02 08:30:02 UTC |
runonce: Run Once and Save Result
Description
Package 'runonce' helps automating the saving of long-running code to help running the same code multiple times. If you run some long-running code once, it saves the result in a file on disk. Then, if the result already exists, i.e. if the code has already been run and its output has already been saved, it just reads the result from the stored file instead of running the code again.
Arguments
timing |
Whether to print timing of running code? Default is |
Author(s)
Maintainer: Florian Privé florian.prive.21@gmail.com
See Also
Useful links:
Download once
Description
Download file if does not exist yet.
Usage
download_file(
url,
dir = tempdir(),
fname = url_basename(url),
overwrite = FALSE,
mode = "wb",
...
)
Arguments
url |
URL of file to be downloaded. |
dir |
Directory where to download the file. |
fname |
Base name of the downloaded file ( |
overwrite |
Whether to overwrite? Default is |
mode |
See parameter of |
... |
Arguments passed on to
|
Value
Path to the downloaded (or existing) file.
Examples
download_file("https://github.com/privefl.png")
download_file("https://github.com/privefl.png")
download_file("https://github.com/privefl.png", overwrite = TRUE)
Cache result
Description
Cache the result of code
in an RDS file.
Usage
save_run(code, file, timing = TRUE)
Arguments
code |
Code to run. Do not forget to wrap it with |
file |
File path where the result is stored. Should have extension |
timing |
Whether to print timing of running code? Default is |
Value
The evaluation of code
the first time, the content of file
otherwise.
Examples
# Prepare some temporary file
tmp <- tempfile(fileext = ".rds")
# Run once because result does not exist yet
save_run({
Sys.sleep(2)
1
}, file = tmp)
# Skip run because the result already exists
# (but still output how long it took the first time)
save_run({
Sys.sleep(2)
1
}, file = tmp)
Skip code
Description
Skip code if all conditions are fulfilled. The code should not return anything.
Usage
skip_run_if(code, cond = NULL, files = NULL, timing = TRUE)
Arguments
code |
Code to run. Do not forget to wrap it with |
cond |
Condition to be fulfilled to skip running |
files |
Character vector of file path(s). Default is |
timing |
Whether to print timing of running code? Default is |
Value
NULL
, invisibly.
Examples
# Prepare some temporary file
tmp <- tempfile(fileext = ".txt")
# Run once because file does not exist yet
skip_run_if({
Sys.sleep(2)
write.table(iris, tmp)
}, cond = file.exists(tmp))
# Skip run because `cond` is `TRUE`
skip_run_if({
Sys.sleep(2)
write.table(iris, tmp)
}, cond = file.exists(tmp))
# Skip run because file exists
skip_run_if({
Sys.sleep(2)
write.table(iris, tmp)
}, files = tmp)