Der Arbeitsbereich in R
Der Arbeitsbereich ist deine aktuelle R-Arbeitsumgebung und enthält alle benutzerdefinierten Objekte (Vektoren, Matrizen, Datenrahmen, Listen, Funktionen). Am Ende einer R-Sitzung kann der Nutzer ein Bild des aktuellen Arbeitsbereichs speichern, das beim nächsten Start von R automatisch wieder geladen wird. Die Befehle werden interaktiv am R-Benutzerprompt eingegeben. Die Pfeiltasten nach oben und unten blättern durch deinen Befehlsverlauf.
Wahrscheinlich möchtest du verschiedene Projekte in unterschiedlichen Verzeichnissen aufbewahren. Hier sind einige Standardbefehle zur Verwaltung deines Arbeitsbereichs.
getwd() # print the current working directory - cwd
ls() # list the objects in the current workspace
setwd(mydirectory) # change to mydirectory
setwd("c:/docs/mydir") # note / instead of \ in windows
setwd("/usr/rob/mydir") # on linux
# view and set options for the session
help(options) # learn about available options
options() # view current option settings
options(digits=3) # number of digits to print on output
# work with your previous commands
history() # display last 25 commands
history(max.show=Inf) # display all previous commands
# save your command history
savehistory(file="myfile") # default is ".Rhistory"
# recall your command history
loadhistory(file="myfile")
# default is ".Rhistory"
# save the workspace to the file .RData in the cwd
save.image()
# save specific objects to a file
# if you don't specify the path, the cwd is assumed
save(object list,file="myfile.RData")
# load a workspace into the current session
# if you don't specify the path, the cwd is assumed
load("myfile.RData")
q() # quit R. You will be prompted to save the workspace.
Wichtiger Hinweis für Windows-Benutzer:
R wird verwirrt, wenn du einen Pfad in deinem Code verwendest, wie z.B: R c:\mydocuments\myfile.txt
Das liegt daran, dass R "" als Escape-Zeichen betrachtet. Verwende stattdessen: R c:/meine dokumente/myfile.txt c:/mydokumente/myfile.txt
## To Practice
[This free intro to R course](https://www.datacamp.com/courses/free-introduction-to-r) will get you familiar with the R workspace.