đ Introduction
Before writing your first R program, you need to install R, the programming language, and RStudio, a powerful Integrated Development Environment (IDE) that makes writing, running, and managing R code much easier. While R can be used independently, most developers and data scientists prefer using RStudio because of its user-friendly interface and productivity features.
Information
đ System Requirements
| Component | Requirement |
|---|---|
| Operating System | Windows, macOS, or Linux |
| Memory | Minimum 2 GB RAM (4 GB or more recommended) |
| Storage | Approximately 500 MB of free disk space |
| Internet | Required for downloading installers and packages |
đĨ Installing R
Download the latest version of R from the official Comprehensive R Archive Network (CRAN). Always download R before installing RStudio because RStudio depends on an existing R installation.
Installing R on Windows
- Visit the CRAN website.
- Select Download R for Windows.
- Click base.
- Download the latest installer.
- Run the installer using the default options.
Installing R on macOS
- Visit the CRAN website.
- Select Download R for macOS.
- Choose the installer that matches your macOS version.
- Open the downloaded .pkg file.
- Complete the installation wizard.
Installing R on Linux
Most Linux distributions provide R through their package managers.
Ubuntu/Debian Installation
sudo apt update
sudo apt install r-baseTip
đģ Installing RStudio
Once R is installed, download and install RStudio Desktop from the official Posit website.
đĨ Understanding the RStudio Interface
âļī¸ Running Your First R Program
Open a new script by selecting File â New File â R Script, type the following code, and click the Run button or press Ctrl + Enter.
Hello World
print("Hello, World!")đĻ Installing Packages
Packages extend R with additional functionality. Install a package once using install.packages() and load it whenever needed using library().
Installing and Loading a Package
install.packages("ggplot2")
library(ggplot2)â Verifying the Installation
You can verify that both R and RStudio are installed correctly by checking the installed R version.
Check R Version
R.version.stringSuccess
â ī¸ Common Installation Issues
| Problem | Possible Solution |
|---|---|
| RStudio cannot find R | Install R before installing RStudio. |
| Package installation fails | Check your internet connection and CRAN mirror. |
| Permission denied | Run the installer with administrator privileges. |
| Old R version | Download the latest release from CRAN. |
đĄ Best Practices
- Always install R before installing RStudio.
- Keep both R and RStudio updated to the latest stable versions.
- Create separate projects for different tasks.
- Install only trusted packages from CRAN.
- Save your work frequently using .R script files.
Best Practice
đ Installation Workflow
đ Summary
Installing R and RStudio is the first step toward learning data analysis, statistical computing, and machine learning with R. By installing R from CRAN and RStudio from the official Posit website, you gain a powerful environment for writing, testing, and managing R programs efficiently. Once the installation is complete, you are ready to explore the fundamentals of the R programming language and begin building data-driven applications.