HenrikBengtsson / startup

:wrench: R package: startup - Friendly R Startup Configuration
https://henrikbengtsson.github.io/startup/
163 stars 5 forks source link

Add function to compile all Rprofile files into a single one #43

Open HenrikBengtsson opened 6 years ago

HenrikBengtsson commented 6 years ago

Add a function startup::compile() to compile all Rprofile script files into a single Rprofile file where the directory and file name filters are translated into if statements. For example, the content of file ~/.Rprofile.d/os=windows/work,interactive=TRUE.R should be injected with the following if statement/wrapper:

## Tags: os=windows, interactive=TRUE
if ( startup::sysinfo()$os == "windows" && startup::sysinfo()$interactive ) {
  [... file content here ...]
}

There could also be an option to make the compiled script not dependent on the startup package, i.e. by - something like:

if ( .Platform$OS.type == "windows" && interactive() ) {
  [... file content here ...]
}

Other conditions may be a bit more convoluted and requires complex R code, but the gist is the same.

Compiling into a single file may make the overall processing time to go down because fewer files are accessed. It may also help troubleshooting.

See also https://github.com/HenrikBengtsson/bash-startup/issues/5

UPDATE 2018-04-29: the value of the conditional variables should be done upfront/at the beginning only - the filtering a files is only done ones and a processed file cannot change affect the filtering.