Skip to contents

load an R session

Usage

load_jamsession(
  session,
  sessions_path = jamsession_paths()$sessions,
  save_date = NULL,
  envir = globalenv(),
  assign_session = TRUE,
  load_history = TRUE,
  do_prompt = TRUE,
  do_window_title = 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(). This value can also match rownames() on list_jamsessions() so that it can include a specific 'save_date'.

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. Note that the argument 'session' can accept this string as suffix, 'sessionname_savedate'.

  • 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 default TRUE, whether to assign session to the parent.env(), typically the global environment globalenv().

load_history

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

do_prompt

logical default TRUE, whether to set the R prompt with jamba::setPrompt() to include the session name.

do_window_title

logical default TRUE, whether to update the graphics device options to include the session name in the title. When TRUE, it calls quartz.options(), X11.options(), and windows.options() where available.

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

Other jamsession sessions: grep_jamsessions(), save_jamsession(), show_session_versions()