savews {rwm}R Documentation

Save workspace

Description

Save R workspace and history.

Usage

savews(name = .WSID, d = as.character(.UserDate), silentQ = FALSE, 
      historyQ = TRUE, q = FALSE, prefix = .Prefix)

Arguments

name name of workspace
d usually year but could be any other part
silentQ TRUE, no message
historyQ TRUE, save R history
q quit R, FALSE - no; TRUE - yes quit
prefix Default workspace filename is ‘.Rdata’ but if prefix is a valid non-null character string, it will be prepended to “.Rdata”. If the argument prefix is not supplied and if .Prefix does not exist, prefix is set to NULL.

Details

First the working directory is changed to that specified by the arguments. The working directory is specified by concatenating ‘.UserDirectory’ <> “d” <> ‘name’ unless ‘name’ is set to its default .WSID. In this case the working directory is simply .WSID. Then save.image(.Rdata) and savehistory(.Rhistory) are used. The global variable .WSID is set to the working directory. If prefix is supplied, it is prepended to “.Rdata” and to “.Rhistory”.

An error message is given if .UserDirectory is not defined. The .UserDirectory may be set manually using a normal R assignment or by the function IntializeRWM.

A warning is given if prefix is invalid. In this case the workspace is saved as “.Rdata”.

Value

Just before saving, the following is done:

1 the global variable .WSID is set to the working directory for the saved workspace
2 the global variable .UserDate is set
3 if prefix is non-Null, the global variable .Prefix is set

Note

savews() is a useful shortcut. It saves the current workspace in the same file it was in when loaded.

Author(s)

A.I. McLeod

See Also

load, savews, clearws, initrwm

Examples


#INITIALIZATION
#Normally .UserDirectory and .UserDate are defined previously. 
#Usually a more convenient directory is used but for illustration
#using a script which will run in interactive or batch mode on any computer:
.UserDirectory <- tempdir()
.UserDate <- "2008"
dir.create(paste(.UserDirectory, .UserDate, sep="/"))

#Example 1. Define function to compute all primes <=n
#Save this and also a list of all primes less than 200
primes <-  function(n){
 (2:n)[apply(outer(2:n, 2:n, FUN="%%")==0, MARGIN=1, sum)==1]
 }
ListPrimes<-primes(200)
savews("Primes")
#Now that .WSID has been defined, you can save this workspace with
savews()
#Notice that an error is produced if the argument 'name' is not a 
#  character string
## Not run: 
savews(Primes)
## End(Not run)

#Example 2. Compute a larger list and save new results
ListPrimes<-primes(1000)
savews()
# Note that no argument is required for 'savews()'


[Package rwm version 1.35 Index]