Getting Started with R: A Step-by-Step Guide
R is a versatile, high-level programming language widely supported across all major operating systems. In this guide, we will walk you through the process of running R online and installing it on your computer.
Running R Online
To run R online, you can use our free online R editor. This online editor enables you to run R code directly in your browser without requiring any installation.
Installing R on Your Computer
To install R on your computer, follow these steps:
For Windows Users
- Install VS Code: Go to the VS Code official website and download the Windows installer. Once the download is complete, run the installer and follow the installation process.
- Download the R Installer File: Go to the official R Project website and download the latest version of R for Windows.
- Run the Installer: Go to your download folder and run the installer you just downloaded.
- Install R: Choose your preferred language and installation path. The installer will then prompt you to choose components and where to place shortcuts.
- Add R to the PATH Environment Variable: Manually ensure your system’s PATH environment variable is set correctly.
- Verify the Installation: Open a command prompt (cmd) and type
R --version
to verify that R is installed successfully.
For Mac Users
- Install VS Code: Go to the VS Code official website and download the zipped file. Once the download is complete, open the zipped file and drag it into the Applications folder.
- Install Homebrew: Open the Terminal app and type the command to install Homebrew (if it’s not already installed).
- Install R: Use Homebrew to install R by entering the command
brew install r
. - Verify the Installation: Open the Terminal and type
R --version
to verify that R is installed correctly.
For Linux Users (Ubuntu Distribution)
- Install VS Code: Open the Terminal and type the command to install VS Code.
- Add CRAN Package: Add the CRAN package to your system using the command
sudo apt-get install r-cran
. - Add CRAN gpg Key: Add the CRAN gpg key using the command
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
. - Install r-base: Install the complete R system using the command
sudo apt-get install r-base
. - Verify the Installation: Open the Terminal and type
R --version
to verify that R is installed successfully.
Running Your First R Program
- Open VS Code: Click on File in the top menu and select New File.
- Save the File: Save the file with a
.r
extension by clicking on File again, then Save As, and type your filename ending in.r
. - Install R Extension: Ensure the R extension is installed in VS Code by clicking on Extensions on the left sidebar and searching for the R extension.
- Write the Code: Write the following code into your file:
print("Hello, World")
. - Run the Code: Click the run button on the top right side of your screen to see the output.
Congratulations! You have now set up everything to run R programs on your computer. In the next tutorial, you will learn how R’s basic program works.