February 10, 2024
The working directory in R is the folder where we are working.
Store files or load them
R Objects are saved
To check the directory of a R session, use the function getwd()
setwd() function
To change the working directory, we use setwd()
function
We must specify the path of new working directory folder
Change working directory in RStudio
In order to create a new directory go to Session
\(\rightarrow\) Set Working Directory
Select the option there
Check the working directory
Change the working directory
Projects allow you to keep a collection of files all together, including:
R scripts
RMarkdown files (more on this later)
Data files
And much more!
very useful to organize our scripts in folders
when opening a project, it will contain all the files corresponding to it. Also, the project folder will be set as the working directory
sets the working directory and makes relative path
. . .
There are two main file types that you’ll work with
. . .
While you can run/execute r code using R console
with ease.
It is time consuming.
Each time you have to re-enter a command to execute it.
Be calm, we have solution that is R scripts
A script is simply a text file containing a set of commands and comments. The script can be saved and used later to re-execute the saved commands. The script can also be edited so you can execute a modified version of the commands.
Create new script file: File -> New File -> R Script
What is R package?
A collection of code related to specific tasks
As of Today, there are 20429 Packages
Packages relevant to specific area can be viewed at CRANTASKVIEW
How to use a package?
install.packages("package name")
library(package name)
data.table
readxl
Create a Project
Create a script file
Install TWO packages using script file
THANKS