Title: | Apply Mapping Functions in Frequent Saving |
---|---|
Description: | Implementations of the family of map() functions with frequent saving of the intermediate results. The contained functions let you start the evaluation of the iterations where you stopped (reading the already evaluated ones from cache), and work with the currently evaluated iterations while remaining ones are running in a background job. Parallel computing is also easier with the workers parameter. |
Authors: | Marcell Granat [aut, cre] |
Maintainer: | Marcell Granat <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.2 |
Built: | 2025-03-01 05:21:53 UTC |
Source: | https://github.com/marcellgranat/currr |
purrr::map
. Apply a function to each element of a vector, but save the intermediate data after a given number of iterations.The map functions transform their input by applying a function to
each element of a list or atomic vector and returning an object of
the same length as the input. cp_map
functions work exactly the
same way, but creates a secret folder in your current working directory
and saves the results if they reach a given checkpoint. This way
if you rerun the code, it reads the result from the cache folder
and start to evalutate where you finished.
cp_map()
always returns a list.
map_lgl()
, map_dbl()
and map_chr()
return an
atomic vector of the indicated type (or die trying). For these functions,
.f
must return a length-1 vector of the appropriate type.
cp_map(.x, .f, ..., name = NULL, cp_options = list())
cp_map(.x, .f, ..., name = NULL, cp_options = list())
.x |
A list or atomic vector. |
.f |
A function, specified in one of the following ways:
|
... |
Additional arguments passed on to the mapped function. |
name |
Name for the subfolder in the cache folder. If you do not specify,
then |
cp_options |
Options for the evaluation:
You can set these options also with |
A list.
Other map variants:
cp_map_chr()
,
cp_map_dbl()
,
cp_map_dfc()
,
cp_map_dfr()
,
cp_map_lgl()
# Run them on console! # (functions need writing and reading access to your working directory and they also print) avg_n <- function(.data, .col, x) { Sys.sleep(.01) .data |> dplyr::pull({{ .col }}) |> (\(m) mean(m) * x) () } cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = 2, name = "iris_mean") # same function, read from cache cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = 2, name = "iris_mean") remove_currr_cache()
# Run them on console! # (functions need writing and reading access to your working directory and they also print) avg_n <- function(.data, .col, x) { Sys.sleep(.01) .data |> dplyr::pull({{ .col }}) |> (\(m) mean(m) * x) () } cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = 2, name = "iris_mean") # same function, read from cache cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = 2, name = "iris_mean") remove_currr_cache()
purrr::map
. Apply a function to each element of a vector, but save the intermediate data after a given number of iterations.The map functions transform their input by applying a function to
each element of a list or atomic vector and returning an object of
the same length as the input. cp_map
functions work exactly the
same way, but creates a secret folder in your current working directory
and saves the results if they reach a given checkpoint. This way
if you rerun the code, it reads the result from the cache folder
and start to evalutate where you finished.
cp_map()
always returns a list.
map_lgl()
, map_dbl()
and map_chr()
return an
atomic vector of the indicated type (or die trying). For these functions,
.f
must return a length-1 vector of the appropriate type.
cp_map_chr(.x, .f, ..., name = NULL, cp_options = list())
cp_map_chr(.x, .f, ..., name = NULL, cp_options = list())
.x |
A list or atomic vector. |
.f |
A function, specified in one of the following ways:
|
... |
Additional arguments passed on to the mapped function. |
name |
Name for the subfolder in the cache folder. If you do not specify,
then |
cp_options |
Options for the evaluation:
You can set these options also with |
A character vector.
Other map variants:
cp_map()
,
cp_map_dbl()
,
cp_map_dfc()
,
cp_map_dfr()
,
cp_map_lgl()
# Run them on console! # (functions need writing and reading access to your working directory and they also print) avg_n <- function(.data, .col, x) { Sys.sleep(.01) .data |> dplyr::pull({{ .col }}) |> (\(m) mean(m) * x) () } cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = Sepal.Length, name = "iris_mean") # same function, read from cache cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = Sepal.Length, name = "iris_mean") remove_currr_cache()
# Run them on console! # (functions need writing and reading access to your working directory and they also print) avg_n <- function(.data, .col, x) { Sys.sleep(.01) .data |> dplyr::pull({{ .col }}) |> (\(m) mean(m) * x) () } cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = Sepal.Length, name = "iris_mean") # same function, read from cache cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = Sepal.Length, name = "iris_mean") remove_currr_cache()
purrr::map
. Apply a function to each element of a vector, but save the intermediate data after a given number of iterations.The map functions transform their input by applying a function to
each element of a list or atomic vector and returning an object of
the same length as the input. cp_map
functions work exactly the
same way, but creates a secret folder in your current working directory
and saves the results if they reach a given checkpoint. This way
if you rerun the code, it reads the result from the cache folder
and start to evalutate where you finished.
cp_map()
always returns a list.
map_lgl()
, map_dbl()
and map_chr()
return an
atomic vector of the indicated type (or die trying). For these functions,
.f
must return a length-1 vector of the appropriate type.
cp_map_dbl(.x, .f, ..., name = NULL, cp_options = list())
cp_map_dbl(.x, .f, ..., name = NULL, cp_options = list())
.x |
A list or atomic vector. |
.f |
A function, specified in one of the following ways:
|
... |
Additional arguments passed on to the mapped function. |
name |
Name for the subfolder in the cache folder. If you do not specify,
then |
cp_options |
Options for the evaluation:
You can set these options also with |
A numeric vector.
Other map variants:
cp_map()
,
cp_map_chr()
,
cp_map_dfc()
,
cp_map_dfr()
,
cp_map_lgl()
# Run them on console! # (functions need writing and reading access to your working directory and they also print) avg_n <- function(.data, .col, x) { Sys.sleep(.01) .data |> dplyr::pull({{ .col }}) |> (\(m) mean(m) * x) () } cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = Sepal.Length, name = "iris_mean") # same function, read from cache cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = Sepal.Length, name = "iris_mean") remove_currr_cache()
# Run them on console! # (functions need writing and reading access to your working directory and they also print) avg_n <- function(.data, .col, x) { Sys.sleep(.01) .data |> dplyr::pull({{ .col }}) |> (\(m) mean(m) * x) () } cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = Sepal.Length, name = "iris_mean") # same function, read from cache cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = Sepal.Length, name = "iris_mean") remove_currr_cache()
purrr::map
. Apply a function to each element of a vector, but save the intermediate data after a given number of iterations.The map functions transform their input by applying a function to
each element of a list or atomic vector and returning an object of
the same length as the input. cp_map
functions work exactly the
same way, but creates a secret folder in your current working directory
and saves the results if they reach a given checkpoint. This way
if you rerun the code, it reads the result from the cache folder
and start to evalutate where you finished.
cp_map()
always returns a list.
map_lgl()
, map_dbl()
and map_chr()
return an
atomic vector of the indicated type (or die trying). For these functions,
.f
must return a length-1 vector of the appropriate type.
cp_map_dfc(.x, .f, ..., name = NULL, cp_options = list())
cp_map_dfc(.x, .f, ..., name = NULL, cp_options = list())
.x |
A list or atomic vector. |
.f |
A function, specified in one of the following ways:
|
... |
Additional arguments passed on to the mapped function. |
name |
Name for the subfolder in the cache folder. If you do not specify,
then |
cp_options |
Options for the evaluation:
You can set these options also with |
A tibble.
Other map variants:
cp_map()
,
cp_map_chr()
,
cp_map_dbl()
,
cp_map_dfr()
,
cp_map_lgl()
# Run them on console! # (functions need writing and reading access to your working directory and they also print) avg_n <- function(.data, .col, x) { Sys.sleep(.01) .data |> dplyr::pull({{ .col }}) |> (\(m) mean(m) * x) () } cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = Sepal.Length, name = "iris_mean") # same function, read from cache cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = Sepal.Length, name = "iris_mean") remove_currr_cache()
# Run them on console! # (functions need writing and reading access to your working directory and they also print) avg_n <- function(.data, .col, x) { Sys.sleep(.01) .data |> dplyr::pull({{ .col }}) |> (\(m) mean(m) * x) () } cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = Sepal.Length, name = "iris_mean") # same function, read from cache cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = Sepal.Length, name = "iris_mean") remove_currr_cache()
purrr::map
. Apply a function to each element of a vector, but save the intermediate data after a given number of iterations.The map functions transform their input by applying a function to
each element of a list or atomic vector and returning an object of
the same length as the input. cp_map
functions work exactly the
same way, but creates a secret folder in your current working directory
and saves the results if they reach a given checkpoint. This way
if you rerun the code, it reads the result from the cache folder
and start to evalutate where you finished.
cp_map()
always returns a list.
map_lgl()
, map_dbl()
and map_chr()
return an
atomic vector of the indicated type (or die trying). For these functions,
.f
must return a length-1 vector of the appropriate type.
cp_map_dfr(.x, .f, ..., name = NULL, cp_options = list())
cp_map_dfr(.x, .f, ..., name = NULL, cp_options = list())
.x |
A list or atomic vector. |
.f |
A function, specified in one of the following ways:
|
... |
Additional arguments passed on to the mapped function. |
name |
Name for the subfolder in the cache folder. If you do not specify,
then |
cp_options |
Options for the evaluation:
You can set these options also with |
A tibble.
Other map variants:
cp_map()
,
cp_map_chr()
,
cp_map_dbl()
,
cp_map_dfc()
,
cp_map_lgl()
# Run them on console! # (functions need writing and reading access to your working directory and they also print) avg_n <- function(.data, .col, x) { Sys.sleep(.01) .data |> dplyr::pull({{ .col }}) |> (\(m) mean(m) * x) () } cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = Sepal.Length, name = "iris_mean") # same function, read from cache cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = Sepal.Length, name = "iris_mean") remove_currr_cache()
# Run them on console! # (functions need writing and reading access to your working directory and they also print) avg_n <- function(.data, .col, x) { Sys.sleep(.01) .data |> dplyr::pull({{ .col }}) |> (\(m) mean(m) * x) () } cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = Sepal.Length, name = "iris_mean") # same function, read from cache cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = Sepal.Length, name = "iris_mean") remove_currr_cache()
purrr::map
. Apply a function to each element of a vector, but save the intermediate data after a given number of iterations.The map functions transform their input by applying a function to
each element of a list or atomic vector and returning an object of
the same length as the input. cp_map
functions work exactly the
same way, but creates a secret folder in your current working directory
and saves the results if they reach a given checkpoint. This way
if you rerun the code, it reads the result from the cache folder
and start to evalutate where you finished.
cp_map()
always returns a list.
map_lgl()
, map_dbl()
and map_chr()
return an
atomic vector of the indicated type (or die trying). For these functions,
.f
must return a length-1 vector of the appropriate type.
cp_map_lgl(.x, .f, ..., name = NULL, cp_options = list())
cp_map_lgl(.x, .f, ..., name = NULL, cp_options = list())
.x |
A list or atomic vector. |
.f |
A function, specified in one of the following ways:
|
... |
Additional arguments passed on to the mapped function. |
name |
Name for the subfolder in the cache folder. If you do not specify,
then |
cp_options |
Options for the evaluation:
You can set these options also with |
A logical vector.
Other map variants:
cp_map()
,
cp_map_chr()
,
cp_map_dbl()
,
cp_map_dfc()
,
cp_map_dfr()
# Run them on console! # (functions need writing and reading access to your working directory and they also print) avg_n <- function(.data, .col, x) { Sys.sleep(.01) .data |> dplyr::pull({{ .col }}) |> (\(m) mean(m) * x) () } cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = Sepal.Length, name = "iris_mean") # same function, read from cache cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = Sepal.Length, name = "iris_mean") remove_currr_cache()
# Run them on console! # (functions need writing and reading access to your working directory and they also print) avg_n <- function(.data, .col, x) { Sys.sleep(.01) .data |> dplyr::pull({{ .col }}) |> (\(m) mean(m) * x) () } cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = Sepal.Length, name = "iris_mean") # same function, read from cache cp_map(.x = 1:10, .f = avg_n, .data = iris, .col = Sepal.Length, name = "iris_mean") remove_currr_cache()
Remove currr's intermediate data from the folder.
remove_currr_cache(list = NULL)
remove_currr_cache(list = NULL)
list |
A character vector specifying the name of the caches you want to remove (files in .currr.data folder). If empy (default), all caches will be removed. |
No return value, called for side effects
Run a map with the function, but saves after a given number of execution. This is an internal function, you are not supposed to use it manually, but can call for background job inly if exported.
saving_map(.ids, .f, name, n_checkpoint = 100, currr_folder, ...)
saving_map(.ids, .f, name, n_checkpoint = 100, currr_folder, ...)
.ids |
Placement of .x to work with. |
.f |
Called function. |
name |
Name for saving. |
n_checkpoint |
Number of checkpoints. |
currr_folder |
Folder where cache files are stored. |
... |
Additionals. |
No return value, called for side effects
Run a map with the function, but saves after a given number of execution. This is an internal function, you are not supposed to use it manually, but can call for background job only if exported. This function differs from saving_map, since it does not have a ... input. This is neccessary because job::job fails if ... is not provided for the cp_map call.
saving_map_nodot(.ids, .f, name, n_checkpoint = 100, currr_folder)
saving_map_nodot(.ids, .f, name, n_checkpoint = 100, currr_folder)
.ids |
Placement of .x to work with. |
.f |
Called function. |
name |
Name for saving. |
n_checkpoint |
Number of checkpoints. |
currr_folder |
Folder where cache files are stored. |
No return value, called for side effects