Introduction to R
NPTEL NOC18-CS28
Data science for Engineers
In this lecture
How to
◦ add comments
◦ clear the environment
◦ saving the workspace
R Basics NPTEL NOC18-CS28 2
Data science for Engineers
Add comments –single line
For single line comment, insert ‘#’ at the start of the line
R Basics NPTEL NOC18-CS28 3
Data science for Engineers
Add comments –Multiple lines
Two ways:
1) Select multiple lines using
cursor, then press “Ctrl +
Shift + C”
(OR)
2) Select multiple lines
using cursor, click on
“Code” in menu and select
“Comment/Uncomment
lines”
R Basics NPTEL NOC18-CS28 4
Data science for Engineers
Clear the console
“control +L”
Ctlr + L
R Basics NPTEL NOC18-CS28 5
Data science for Engineers
Clear the environment –rm()
Single variable: Enter in console/R script : rm(variable)
All variables: Enter in console/R script : rm(list=ls())
OR
R Basics NPTEL NOC18-CS28 6
Data science for Engineers
Confirmation dialog
R Basics NPTEL NOC18-CS28 7
Data science for Engineers
Empty environment
R Basics NPTEL NOC18-CS28 8
Data science for Engineers
Saving data from workspace
Workspace data
Workspace information is temporary
Is not retained after the session
◦ If you close the R-session
◦ If you restart the computer
R Basics NPTEL NOC18-CS28 9
Data science for Engineers
Automatic option
R Basics NPTEL NOC18-CS28 10
Data science for Engineers
Manual saving
Can be permanently saved in a file – save command
Can be reloaded for future sessions – load command
# Example code
save(a, file=“sess1.Rdata”) # to save a single variable ‘a’
# to save a full workspace with specified file name
save(list=ls(all.names=TRUE), file=“sess1.Rdata”)
save.image() # short cut function to save whole workspace
load(file=“sess1.Rdata”) # to load saved workspace
R Basics NPTEL NOC18-CS28 11