- Install R from https://cran.rstudio.com/
- Download RStudio Desktop from https://rstudio.com/products/rstudio/download/#download
You can set appearance and pane layout in Menu Tools > Global Options...
In R Studio compose of 4 Pane:
- Source: for script file
- Concole: for watch result from running
- Environment: show variable that you have assign
- Files, Plots, Packages, Help: show other information
In this part you need to get and set working directory of program RStudio Desktop. It has 3 Step
- Step 1: Get working directory by using
getwd()
- Step 2: Create new folder then set working directory to this folder by using
setwd("path")
- Step 3: Try to add some file then check it that you are setting directory right.
#Get Working Directory
getwd()
#Set Working Directory
setwd("path")
#List the Files in a Directory/Folder
dir()
open terminal app and then go to your folder with cd
then using command pwd
to print working directory
#Terminal App (Sample)
jatawatsafe@Safe-MBP ~ % pwd
/Users/jatawatsafe
jatawatsafe@Safe-MBP ~ % ls
Desktop Library Postman
jatawatsafe@Safe-MBP ~ % cd Desktop/R-214
jatawatsafe@Safe-MBP R-214 % pwd
/Users/jatawatsafe/Desktop/R-214
# Back to R and put this path in setwd()
setwd("/Users/jatawatsafe/Desktop/R-214")
#Linux command in Terminal
ls #List file
cd folderName/folderName #Change directory
pwd #Print Working Directory
- Open File Explorer and go to your folder
- Right click at navigate and copy your address (or use another ways)
- Put in command
setwd()
and change\
to/
***If not change it will Error
# When you get path from address:
# C:\Users\safe\Desktop\R-INT214
# When using in R
setwd("C:/Users/safe/Desktop/R-INT214")
Create file test.txt
in your folder then go to console in R Studio and using dir()
to list all files in working directory
Open Terminal app (make sure that you are right working directory by using pwd
to check) try to create new file by using command touch test.txt
to create blank file
Right click on your folder select New > Text Document
then save it to folder.
Setting default working directory by use menu Session > Set working directory > Choose...
Try to run this in console...
#comment
1+1
# formula
2*100 - 5
# Print function
print("Hello")
3.1. Create Script file and save 1-MyScript.R
3.2. copy code in Topic 2 and paste in script file.
3.3. Run Script
Command+Enter
Run the current line or selectionCommand+option+R
Run allCtrl+L
Clear console
We can create variable by using <-
it mean assign value (right) to variable (left)
# create variable
x <- 1
y <- 2
x+y
print(x + y)
z <- x+y
z
# Directory
getwd()
setwd()
# Help Function
?
help()