HenrikBengtsson / startup

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

Support for when={once,hourly,weekly,fortnightly,monthly} directives #66

Closed HenrikBengtsson closed 5 years ago

HenrikBengtsson commented 5 years ago

Just a heads up and call for testing and feedback. I'm prototyping support for processing R startup files (under ~/.Renviron.d/ and ~/.Rprofile.d/) with certain periodicity. In the feature/agenda develop branch, you'll now find:

For example, the startup file ~/.Rprofile.d/interactive=TRUE/when=hourly/package=fortunes.R will be processed at most once an hour whenever you launch an interactive R session and you have the 'fortures' package installed. So, to show a random fortune at startup once an hour, do something like:

local({
  f <- suppressWarnings(fortunes::fortune())
  cat(sprintf("Fortune #%s:\n", attr(f, "row.names")))
  print(f)
  unloadNamespace("fortunes")
}

To test it, install it as:

remotes:install_github("HenrikBengtsson/startup@develop")

PS. The naming convention is taken from anacron.

UPDATE 2019-03-22: Merged these features in to the 'develop' branch.

HenrikBengtsson commented 5 years ago

Should probably add an argument and corresponding environment variable to force the running off all when statements. Maybe this could be done by overriding the current time, which also would have the advantage to emulate different timestamps. For example:

$ R_STARTUP_TIME="2019-03-26 11:41:20" R

UPDATE: Although R_STARTUP_TIME can fake a future timestamp, we might also want to be able to clear the cache, e.g.

$ R_STARTUP_CACHE="reset" R

which by the way can also be done as:

$ Rscript -e "startup:::reset_when_cache()"; R

UPDATE 2019-05-26: Renamed internal reset_agenda() to reset_when_cache().

HenrikBengtsson commented 5 years ago

startup::reset_when_cache() is now exported.