sourceIfChanged: Source a file, but only if it changed from the last time you...

View source: R/sourceIfChanged.R

sourceIfChangedR Documentation

Source a file, but only if it changed from the last time you ran sourceIfChanged() on the file

Description

Rather than sourcing your analysis script many times, which can be cumbersome, this script skips the sourcing if there is a .log file that matches the sourced file. If that matching .log file exists, the corresponding .RData file is loaded. Otherwise, the file is sourced and both .log and .RData files are created.

Usage

sourceIfChanged(filepath)

Arguments

filepath

.R file to source

The intended use is largely for when the user wants reproducible results (sometimes requiring long analyses) while writing .Rmarkdown documents. While working with the main text, formatting, and such, it's nice to just load pre-run data rather than waiting to source every time.

There are important implications, such as the fact that only the sourced file is checked for changes, and therefore the old data will be loaded even if other things (e.g., global variables) have been changed.


akcochrane/ACmisc documentation built on Nov. 24, 2024, 11:22 a.m.