load an R session

load_jamsession(
  session,
  sessions_path = jamsession_paths()$sessions,
  save_date = NULL,
  envir = globalenv(),
  assign_session = TRUE,
  load_history = TRUE,
  do_window_title = TRUE,
  do_prompt = TRUE,
  verbose = TRUE,
  ...
)

Arguments

session

character string corresponding to the "session", which is matched directly with the "session" column output from grep_jamsessions(), or data.frame output from grep_jamsessions().

sessions_path

character vector of one or more file paths to search for saved R sessions. When NULL, it uses the output from jamsession_paths()$session. This value is used only when session is a character vector, and is passed to grep_jamsessions().

save_date

optional character string with a specific date to use when loading a session. This string is matched with the "save_date" returned by list_jamsessions(). When save_date is NULL, the most recent session is used, which is the default behavior.

envir

environment, where "environment" %in% class(envir). By default envir uses globalenv() which loads the R session into the workspace. This behavior is intended for new R sessions, to restore the R session to the state it was in when the R session was saved. If loading into an active R session, envir should be defined as a separate environment, in order to prevent R objects in the R session file from overwriting R objects with the same name in the local R workspace. For example session_env=new.env();load_jamsession("New", envir=session_env).

assign_session

logical whether to assign session to the parent.env() which is typically the global environment .GlobalEnv.

load_history

logical whether to load the .Rhistory file for the R session, if available.

do_window_title

logical whether to update the device options to define the title based upon the session. Currently when TRUE, the options quartz.options() and X11.options() are defined, if possible.

do_prompt

logical whether to run jamba::setPrompt() to update the R prompt to include the session.

verbose

logical whether to print verbose output.

...

additional arguments are passed to jamba::setPrompt().

Value

invisible list of R object names loaded into the environment. One could use this vector of R object names to learn which R objects are stored in an R session, by creating a new environment, loading an R session into that environment, then inspecting the R object names.

Details

This function loads a previously-saved R session, loading the most recently saved R session by the session. It also by default sets the R prompt using jamba::setPrompt(), to indicate the session and help reinforce which R session is in the active environment.

The default workflow is to load the R session into the R workspace, that is envir=globalenv(), because the target use for load_jamsession() is to call this function in a new, empty R session in order to continue work on the saved R session. In this case is the .Rhistory file is also available and load_history=TRUE, it is loaded as well. Note that loading R history will overwrite the previous active R history.

However, when envir is defined as something other than globalenv(), then the prompt is not altered, and the R session is loaded into the specific environment. In this case the R history is not loaded, even when load_history=TRUE. When assign_session=TRUE this environment is assigned to a new object in globalenv() so that it can be attached with attach().

See also