onetime_only | R Documentation |
This takes a function and returns the same function wrapped by onetime_do()
.
Use it for code which should run only once, but which may be called from
multiple locations. This frees you from having to use the same id
multiple
times.
onetime_only(
.f,
id = deprecate_calling_package(),
path = default_lockfile_dir(),
default = NULL,
without_permission = "warn"
)
.f |
A function |
id |
Unique ID string. If this is unset, the name of the calling
package will be used. Since onetime 0.2.0, not setting |
path |
Directory to store lockfiles. The default uses a unique
directory corresponding to the calling package, beneath
|
default |
Value to return from |
without_permission |
Character string. What to do if the user hasn't
given permission to store files? |
A wrapped function. The function itself returns the result of .f
,
or default
if the inner function was not called.
onetime_do()
oo <- options(onetime.dir = tempdir(check = TRUE))
id <- sample(10000L, 1)
sample_once <- onetime_only(sample, id = id)
sample_once(1:10)
sample_once(1:10)
onetime_reset(id)
options(oo)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.