The workspace is your current R working environment and includes any user-defined objects (vectors, matrices, data frames, lists, functions). At the end of an R session, the user can save an image of the current workspace that is automatically reloaded the next time R is started. Commands are entered interactively at the R user prompt. Up and down arrow keys scroll through your command history.
You will probably want to keep different projects in different physical directories. Here are some standard commands for managing your workspace.
getwd()# print the current working directory - cwd
ls()# list the objects in the current workspaceDrivs av
setwd(mydirectory)# change to mydirectory
setwd("c:/docs/mydir")# note / instead of \ in windows
setwd("/usr/rob/mydir")# on linuxDrivs av
# 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 outputDrivs av
# 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"Drivs av
# 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")Drivs av
# load a workspace into the current session# if you don't specify the path, the cwd is assumed
load("myfile.RData")Drivs av
q()# quit R. You will be prompted to save the workspace.Drivs av
Important Note to Windows Users:
R gets confused if you use a path in your code like: R c:\mydocuments\myfile.txt This is because R sees "" as an escape character. Instead, use: ```R c:\my documents\myfile.txt c:/mydocuments/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.
Drivs av
The workspace is your current R working environment and includes any user-defined objects (vectors, matrices, data frames, lists, functions). At the end of an R session, the user can save an image of the current workspace that is automatically reloaded the next time R is started. Commands are entered interactively at the R user prompt. Up and down arrow keys scroll through your command history.
You will probably want to keep different projects in different physical directories. Here are some standard commands for managing your workspace.
Important Note to Windows Users:
R gets confused if you use a path in your code like:
R c:\mydocuments\myfile.txtThis is because R sees "" as an escape character. Instead, use: ```R c:\my documents\myfile.txt c:/mydocuments/myfile.txt