save.session <- function(file, ...) {
if (startsWith(file, ".")) {
error("Must not be a hidden file")
} else if (!is.null(dev.list())) {
## Got this line from the sessions package
warning("Open graphics devices will be neither saved nor restored")
}
## now make the top-level dir folder for all saved
if (!dir.exists("Saved_R_Sessions")) {
## we need to create a top-level folder
dir.create("Saved_R_Sessions")
}
## make the completed path for the folder with the info and the session itself
## @TO_DO: Write a session info function that returns the information
## from that file
.full.path <- paste("Saved_R_Sessions/", file, sep="")
if (!dir.exists(.full.path)) {
## print("Not found")
dir.create(.full.path)
}
## next 2 lines from the "sessions" package
.save.session.search <<- search()
.save.session.packages <<- .packages()
## NOTE: Keep these hidden in case the user has some variable named either
## of the above in the environment
.save.file.path <- paste(.full.path, "/", file,
".RSession", sep = "")
save(list = ls(envir = .GlobalEnv, all.names = TRUE), file = .save.file.path, ...)
## now we write the info
.file.name <- paste(.full.path, "/", file,
"_info", sep="")
.out <- sessionInfo()
save(.out, file = .file.name)
cat("Successfully saved session! :)", "\n")
## instead of print so that we can not have the [1] ... thingy
}
#' @title Save Current R Session with Custom Name
#'
#' @name save.session
#'
#' @description Given a string \code{name}, the function will save your
#' current R. The session will be located in ~/Saved_R_Sessions/\code{name}.
#'
#' @param \code{name} A string value naming the session about which you
#' wish to learn.
#'
#' @param \code{...} Additional arguments passed to \link{save()}[save].
#'
#' @return NULL.
#'
#' @details If no directory exists for either the sessions or a session with
#' that name, the function will create those folders.
#'
#' @keywords save, load, sessions, shiny, CMU
#'
#' @export
"save.session"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.