Section 33 Housekeeping Functions

33.1 R Environment

  • To see the R objects created in the current session: objects()

  • To list all R objects: ls()

  • ls() and objects() return a vector of character strings giving the names of the objects in the specified environment.

  • To remove an R object: rm(list=c('a','b')) where a and b are two R objects

  • To remove all R objects in the current session: rm(list=ls())

  • To see which packages and dataframes are currently attached: search()

  • Details of the R session: sessionInfo()

33.2 Save Script

  • The easiest way to save the script is to save the file as a .R file within the RStudio environment.

  • The RStudio environment will display an asterisk when the current script is not saved.

33.3 Save History

  • The easiest way to save the history is to save the file as a .Rhistory file within the RStudio environment.

  • The function savehistory can be used to save the history using the function.

  • The function loadhistory helps to load a previously saved history.

33.4 Save an R object

  • The RStudio IDE also helps to save an R object directly.

  • The function save helps to save specific R objects.

  • save(a, b, file='myRobj.RData') where a and b are R objects.

  • The function load helps loading the previously saved R objects or workspace.

33.5 Save Workspace

  • The RStudio IDE also helps to save the entire workspace directly: Session > Save Workspace As

  • The function save.image saves the complete workspace.

  • The function load helps loading the previously saved R objects or workspace.