Getting Started with R

Get started with R and RStudio for data science. Install R, explore its capabilities, and print your first 'Hello World' message.

Why Choose R for Data Science?

R is a powerful programming language and open-source software environment for statistical computing and graphics.

Here are a few reasons why many data scientists prefer to use R:

  • Extensive Data Analysis Capabilities: R provides a wide range of packages and functions for data manipulation, statistical modeling, machine learning, and visualization.
  • Active Community: R has a vibrant and supportive community of users, contributing to the development of packages, providing helpful resources, and sharing knowledge through forums and conferences.
  • Reproducibility and Documentation: R promotes reproducible research by allowing users to write code, document their analyses, and share their work in a transparent manner.

To get started with R, you need to install it on your system. Follow these steps to install R:

  1. Visit the official R website at https://www.r-project.org/.
  2. Click on the “Download” link to access the download page.
  3. Choose your operating system (Windows, macOS, or Linux) and click on the corresponding download link.
  4. Follow the installation instructions specific to your operating system.
  5. Once the installation is complete, you can launch R.

Hello World.

Now that you have R installed, let’s print the famous “Hello World” message. In R, you can use the print() function to display text on the console. Open R and type the following command:

print("Hello World")

I don’t know about you, but I prefer using IDE’s whenever it is possible for my work. This way, many processes in your routine coding sessions can be easily stored for re-using. It is for this reason that we introduce you to Rstudio.

Installing RStudio.

To get started with R, you need to install both R and RStudio. Follow these steps:

  1. Install R: Visit the official R website at https://www.r-project.org/. Click on the “Download” link and choose the appropriate download link for your operating system. Follow the installation instructions for your OS.

  2. Install RStudio: Go to the RStudio website at https://posit.co/. Click on the “Download RSTUDIO” link towards the upper right corner and choose the desired version of RStudio. Note that some versions require a licence and are therefore not offered for free. Fortunately for many individual users, the free Desktop version is more than sufficient for us, and that is the IDE that we shall be using for all our code. Select the installer for your operating system and follow the installation instructions.

Once both R and RStudio are installed, you can launch RStudio to start working with R.

RStudio Panes.

Labeled Rstudio panes

When working with RStudio, you’ll encounter different panes that provide various functionalities and help you in your data analysis and coding tasks. Here’s a brief overview of the main panes in RStudio:

Source Editor.

The source editor pane is where you write your code. It supports syntax highlighting, auto-completion, and code formatting. You can create, edit, and save R scripts and Markdown documents in this pane.

Console.

The console pane is where you interact with R directly. You can type commands and see the results immediately. It’s useful for testing code snippets, running individual commands, and getting immediate feedback.

Environments/ History.

The environment/history pane displays information about your current R session. It shows the variables in your workspace, their values, and other useful information. You can also access your command history in this pane.

Git/ Viewer/ Build/ Connections.

The git/viewer/build/connections pane offers additional functionality. It integrates with version control systems like Git, provides a viewer for various file types, enables project building and management, and facilitates connections to databases and APIs.

Outputs/ Directory/ Packages/ Help.

The files/plots/packages/help pane provides quick access to various resources. You can navigate and manage your project files, view plots and charts, install and load packages, and access documentation and help files.

Customize Your Layout

You can customize the layout of RStudio according to your preferences. Resize, rearrange, or close panes to create a workspace that suits your needs. You can also save and restore your customized layout using the RStudio session.

That’s a brief overview of the main panes in RStudio. Familiarizing yourself with these panes will help you navigate and utilize the powerful features of RStudio effectively.

Hello World

Now that you have R and RStudio installed, let’s print the famous “Hello World” message in R. In RStudio, open the R console pane and type the following command:

print("Hello World")

Press enter, and R will execute the command and display “Hello World” as the output.

Congratulations! You’re now ready to explore the world of data science with R.

Stay tuned for more exciting R tutorials and tips!