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
characterstring corresponding to the"session", which is matched directly with the"session"column output fromgrep_jamsessions(), ordata.frameoutput fromgrep_jamsessions(). This value can also matchrownames()onlist_jamsessions()so that it can include a specific 'save_date'.- sessions_path
charactervector of one or more file paths to search for saved R sessions. WhenNULL, it uses the output fromjamsession_paths()$session. This value is used only whensessionis a character vector, and is passed togrep_jamsessions().- save_date
optional
characterstring 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 bylist_jamsessions().When
save_dateisNULL, the most recent session is used, which is the default behavior.
- envir
environment, where"environment" %in% class(envir). By defaultenvirusesglobalenv()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,envirshould 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 examplesession_env=new.env();load_jamsession("New", envir=session_env).- assign_session
logicaldefault TRUE, whether to assignsessionto theparent.env(), typically the global environmentglobalenv().- load_history
logicaldefault TRUE, whether to load the '.Rhistory' file for the R session, if available.- do_prompt
logicaldefault TRUE, whether to set the R prompt withjamba::setPrompt()to include the session name.- do_window_title
logicaldefault TRUE, whether to update the graphics device options to include the session name in the title. WhenTRUE, it callsquartz.options(),X11.options(), andwindows.options()where available.- verbose
logicalwhether 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()