HenrikBengtsson / startup

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

restart(): add argument `workdir` to control in what directory to restart #41

Closed HenrikBengtsson closed 6 years ago

HenrikBengtsson commented 6 years ago

Issue

startup::restart() restarts the R session in the current working directory (according to getwd()), e.g.

$ /tmp
$ R --vanilla --quiet
> getwd()
[1] "/tmp"
> setwd("~"); startup::restart()
[...]
> getwd()
[1] "/home/hb"

That is, it does not restart it in the same directory as it was first launched in, which might be what's wanted (at least sometimes).

Suggestion

When using startup::startup(), the startup directory (unless changed prior to calling that function) is recorded internally and available via startup::startup_session_options(), e.g.

$ R --vanilla --quiet
> startup::startup()
> getwd()
[1] "/tmp"
> setwd("~")
> startup::startup_session_options()$startup.session.startdir
[1] "/tmp"
> getwd()
[1] "/home/hb"

The restart() function could be support reset to this folder using something like:

startup::restart(workdir = NULL)  # default

and if one prefer to restart in the current folder, one can use:

startup::restart(workdir = ".")

Also, instead of waiting until startup::startup(), the startup folder should probably be recorded already in .onLoad().