Introduction to R Studio
Tags: datascience, programming, productivity
Published: 2021-01-16 16:02:49

###**Introduction to R Studio**

*__R__*  is a programming language used for Statistical computations, it makes use of an Interactive Integrated Development Environment IDE 
which includes an editor, *__R__* specific features and a console for executing your code 
A newly installed version of  *__R__* is  called *__Base R__* because it is automatically installed with few essential packages after downloading the base subdirectory.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/3w4zex4r2525astjsoga.png)

__While__

*__R Studio__* is an Interactive User Environment that uses the *__R programming language__* to develop the statistical programs , It is neither a programming language or software for developers but simply an Interactive Desktop Environment for *Data Analysis*. It is an indispensable feature in *Data Science* because of its ability to quickly explore data as a necessity of success.
It cannot be used without *__R__*.
 Here are some of its importance:
*    It is free and open-source( it is freely available for end users)
*    It is platform-independent ( it can conveniently run on Mac and Windows etc.)

###**How To Download and Install R Studio** 
#####Step 1: Search for *__R Studio__* on Google ( or any other  browser)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/6g3eiqxlto6fp2e38fo4.png)

#####Step 2: Click on *__R Studio__* From [_CRAN Repository_] (https://cran.r-project.org"CRAN Repository")( The Comprehensive R Archive Network is an *__R Studio__* Repository for downloading the *__R Studio__* )
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/tsbczzs0u3cm48dxczu0.png)

#####Step 3: Click on The Free Desktop Version ( It's safe and affordable, amongst all the other options the free desktop version is a very good download version)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/rgbmlnfzeqddel83twlr.png)

#####Step 4: Find your OS Download Link. (It'll take you to a page where the operating system downloads are available. Find the OS suitable for the device your using)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/0dhatlf5wsm0ahox2wal.png)

#####Step 5: Install *__R Studio__*. After downloading the installation file, click on the downloaded file to start the installation process.![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/v1p13wlecashcqvag1p1.png)

###**First time on R Studio** 
*    On Window Click the start icon and Search *__R Studio__*
*    On Mac, you can find it in the app folder without the mouse to you can click on *__Commands + Space, click enter -__*and start the *__R Studio__*
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/xum9x4pjwqmfach3o21j.png)

*    To start a new script to u can click on *__File > New file > R script__* at the top left corner of the left pane
*    A new pane on the top left will be opened where you can start writing your scripts
###**Key Bindings for running a script or a line of code**
These are keyboard versions of performing tasks that you might want to use concurrently which might be considered strenuous
*    To run a script on R console using a Mac you can use *__Command+Shift+Return__*
using windows you can use Control+Shift+Enter
*    To run a single line of code on the console using a Mac you can use *__Command+Return__*, on Windows you can use (Control+Enter)
*    You can check the latest [*__R Studio Cheatsheet__*](https://rstudio.com/wp-content/uploads/2019/01/Cheatsheets_2019.pdf"R Cheatsheets")
              OR
      *    Click on tools at the top left of the left pane
      *    Click on Cheatsheets
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/o0o29t3o3oxyjdynknfs.png)

      *    Click on R Studio IDE Cheat sheet

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/o6b5e3gauul812qumkec.png)      

###**Getting started with _R Studio_**
####Installing and loading packages on *__R Studio__*
There are two ways of installing *__R Studio__*
1. Using the R Studio to download the package directly from the [*__CRAN Repository__*](https://cran.r-project.org"CRAN Repository")
  *    Click on tools 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/sfj3c2v6ig3y0u5qelnc.png)
  *    Click on Install packages 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/e22qc7vsuewo1mdmhz0x.png)
  *    On  the second bar, you can fill in the name of the package to Install,
here are a few [*__R Studio packages__*](https://support.rstudio.com/hc/en-us/articles/201057987-Quick-list-of-useful-R-packages?mobile_site=true"R packages") you can install.
  *    When installing a package through the *__R Studio__* an advantage to filling the bar is autocomplete, so you can choose from the droplist even when you forget the name of the package
_(Ensure you are connected to the internet when installing a package)_
  *    Afterward, you can load the package with the following code ``library(tidyverse)``   
1. Or you can decide to install the package manually with the following lines of code
  *    Write the code format ``install.packages("tidyverse")`` to install the package 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/48e4ly9wm63rz95ty4nq.png)

  *    To load the packages use the following code ``library("tidyverse")``

  *    You can also install more that one package by putting in a character function using the following code format
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/rtgep4rnyzw4jmg6lrbq.png)

``install.packages(c("tidyverse","dslabs"))``
  *    After running a lot of packages and you want to check the list of packages already installed you can pass in the code format   ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/beysfaat3725zxevqm9e.png)

``installed.packages()`` to check the list of packages already installed

*Note: it is always considered cautious to write down a script of all the basic packages to be installed in a case where the R Studio is to be reset.*
*    Unlike most inbuilt functions in *__R__*, there are few which do not always take in an argument eg ``ls()`` and a few others
*An example is after assigning values to a variable*
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/w1r34mf2f7dym31fma6r.png)

the ``ls()`` function displays a list of the already inputted assignments
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/3wvdy30pdz1pirmd077j.png)

*    Also if you can't remember the arguments to pass in a function or you want to use a function for the first time you can make use of help with the following format to bring a list of all possible arguments you can pass into the function.
*An example is*
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/dj3z4q1bcw0hvj67ej94.png)

OR
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/w2eqqce17kttas8uv9oq.png)

*and here are the possible arguments*
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ws41d9eypc4qs7iq8dfb.png)

*    You can use the following format to print an assignment 
either by writing the variable name only or passing it as an argument to the "print" function
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/xnru0skbbukv1cv1mdci.png)

_Note: To write a comment on R is done by simply beginning a text with a "#" sign and any code coming after the sign will not run._