Exploring the workspace

The working directory

getwd()
[1] "D:/daniel_work/workspace/RExRepos/tmp"
setwd("d:/daniel/work/r/")

Create and remove objects

Create some objects

Aval <- 7
Bval <- 15
Cval <- 10
ls()
 [1] "Aval"        "Bval"        "Cval"        "dirMd"       "dirR"       
 [6] "dirTmp"      "fIn"         "fName"       "fOut"        "markdEngine"
[11] "siteGen"    

List available objects

ls(pattern="C")
[1] "Cval"
exists("Bval")
[1] TRUE
exists("doesNotExist")
[1] FALSE

Remove objects

Aval
[1] 7
rm(Aval)
Aval                             # this will give an error
Error: Objekt 'Aval' nicht gefunden
## rm(list=ls(all.names=TRUE))   # remove all objects from the workspace

Show and rename objects

Show objects

Bval
[1] 15
print(Bval)
[1] 15
(Bval <- 4.5)
[1] 4.5
.Last.value
[1] "nanoc"
get("Bval")
[1] 4.5
varName <- "Bval"
get(varName)
[1] 4.5

Rename objects

ls()
 [1] "Bval"        "Cval"        "dirMd"       "dirR"        "dirTmp"     
 [6] "fIn"         "fName"       "fOut"        "markdEngine" "siteGen"    
[11] "varName"    
newNameVar <- "varNew"
assign(newNameVar, Bval)
varNew
[1] 4.5

Environments and search path

search()
 [1] ".GlobalEnv"        "package:stringr"   "package:knitr"    
 [4] "package:grDevices" "package:datasets"  "package:svSocket" 
 [7] "package:TinnR"     "package:R2HTML"    "package:Hmisc"    
[10] "package:survival"  "package:splines"   "package:graphics" 
[13] "package:stats"     "package:methods"   "package:tcltk"    
[16] "package:utils"     "SciViews:TempEnv"  "Autoloads"        
[19] "package:base"     

How R Searches and Finds Stuff

Session history

By default, savehistory() saves the command history to the file .Rhistory in the current working directory.

history()
savehistory("d:/daniel/work/r/history.r")

By default, save.image() saves all objects in the workspace to the file .RData in the current working directory.

save.image("d:/daniel/work/r/objects.Rdata")

Get the article source from GitHub

R markdown - markdown - R code - all posts