El espacio de trabajo en R
El espacio de trabajo es tu entorno de trabajo R actual e incluye cualquier objeto definido por el usuario (vectores, matrices, marcos de datos, listas, funciones). Al final de una sesión de R, el usuario puede guardar una imagen del espacio de trabajo actual que se recarga automáticamente la próxima vez que se inicie R. Los comandos se introducen interactivamente en el indicador de usuario R. Las teclas de flecha arriba y abajo se desplazan por tu historial de comandos.
Probablemente querrás mantener distintos proyectos en directorios físicos diferentes. Aquí tienes algunos comandos estándar para gestionar tu espacio de trabajo.
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.
Nota importante para los usuarios de Windows:
R se confunde si utilizas una ruta en tu código como R c:\mydocuments\myfile.txt
Esto se debe a que R ve "" como un carácter de escape. En su lugar, utiliza ```R c:misdocumentos/miarchivo.txt c:/misdocumentos/miarchivo.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.