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"),
  log = "INFO",
  .progress = TRUE
)

Arguments

what

(tibble) a tibble as generated by sourcoise_status(), possibly filtered, (defaut to source_status() )

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

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 allows to execute first data that will be used then inside another script with sourcoise(). When a sourcoise("something.r", force_exec=TRUE) is run, inside calls to sourcoise() are not forced. priority is a crude way – yet efficient – to achieve a correct execution with up to date data. Of course, all calls to sourcoise() of the same script should set the same level of priority as the last executed will be kept, with no verification done, so left to the responsability of the user.

See also

Examples

dir <- tempdir()
set_sourcoise_root(dir)
#> [1] "/tmp/Rtmpv54Aer"
fs::file_copy(
   fs::path_package("sourcoise", "ipch", "prix_insee.R"),
   dir,
   overwrite = TRUE)
# Force execution
data <- sourcoise("prix_insee.R", force_exec = TRUE)
# we then refresh all caches
sourcoise_refresh()
#>  prix_insee.r executed in 0 s. for 14 kB of data
#>  Total refresh in 0 seconds for 14 kB of data