Skip to contents

All scripts (passed to sourcoise_refresh()) are executed with logging enabled.

Usage

sourcoise_refresh(
  what = NULL,
  force_exec = TRUE,
  unfreeze = TRUE,
  quiet = FALSE,
  init_fn = getOption("sourcoise.init_fn"),
  root = getOption("sourcoise.root"),
  priotirize = TRUE,
  log = "INFO",
  .progress = TRUE
)

Arguments

what

(tibble) a tibble as generated by sourcoise_status(), possibly filtered, (defaut to source_status() ). What can also be a vector of strings to filter srouces files by name.

force_exec

(boolean) (default FALSE) if TRUE code is executed, no matter what is cached

unfreeze

(boolean) (default TRUE) when possible, unfreeze and uncache .qmd files in a quarto project when data used by those .qmd has been refreshed

quiet

(boolean) (default FALSE) no message if TRUE

init_fn

(function) (default NULL) execute a function before sourcing to allow initialization

root

(default NULL) force root to be set, instead of letting the function finding the root, for advanced uses

priotirize

(boolean) (defaut TRUE) will set priority based on pattern of execution

log

(character) (default "INFO") log levels as in logger::log_threshold() (c("OFF", "INFO", ...)), comes with a small performance cost

.progress

(boolean) (default TRUE) displays a progression bar based on previous execution timings

Value

a list of r scripts (characters) executed, with timing and success and a side effect on caches

Details

The function returns the list of script executed but its main effect is a side-effect as scripts are executed and caches updates accordingly. Note also that log files reflect execution and track possible errors. Because of logging the execution comes with a loss in performance, which is not an issue if scripts are long to execute.

It is possible to execute sourcoise_refresh() without execution forcing (force_exec=FALSE) or with it. Forced execution means that the script is executed even if the cache is valid. In the case of non forced execution, execution is triggered by other cache invalidation tests (change in source file, lapse or tacked files).

When scripts are linked to qmds (i.e. when run in a quarto project), it is possible to unfreeeze and uncache those qmds with the option unfreeze=TRUE. This allows to refresh the cahe and then render the qmds using the new data.

It is possible to pass to refresh a function that will be executed before every script. This allows to load packages and declare global variables that can be used in each script. If packages are loaded inside the script, then this is not needed.

Parameters registered ins sourcoise_status() such as wd or args are used to execute the script.

Defining a priority in sourcoise(), will change the order of execution of refresh. This can be set automatically using priotirize option. After execution of one refresh, by setting higher priority to more used files.

Examples

dir <- tempdir()
set_sourcoise_root(dir)
#> /tmp/Rtmp4DcgLO
fs::file_copy(
   fs::path_package("sourcoise", "some_data.R"),
   dir,
   overwrite = TRUE)
# Force execution
data <- sourcoise("some_data.R", force_exec = TRUE)
# we then refresh all caches
sourcoise_refresh()
#>  Refreshing 1 source files
#>  some_data.R executed in 0 s. , same data (2 kB)
#>  Total refresh in 0 seconds for 2 kB of data