11/9/2019
11

R is a programming language. To use R, we need to install an Integrated Development Environment (IDE). Rstudio is the Best IDE available as it is user-friendly, open-source and is part of the Anaconda platform.

  1. Install Rstudio Mac
  2. Install R Package For Mac

In this tutorial, we will learn

R is a language and environment for statistical computing and graphics. It is a GNU project which is similar to the S language and environment which was developed at Bell Laboratories (formerly AT&T, now Lucent Technologies) by John Chambers and colleagues. R can be considered as a different implementation of S. Sep 22, 2016  Important note for Office 365 subscriptions: After September 22, 2016, Office 2011 for Mac is no longer available for installation with an Office 365 subscription.This doesn't affect one-time purchases of Office for Mac 2011 such as, Office Home and Student, Office Home and Business,. R for Mac OS X. This directory contains binaries for a base distribution and packages to run on Mac OS X (release 10.6 and above). Mac OS 8.6 to 9.2 (and Mac OS X 10.1) are no longer supported but you can find the last supported release of R for these systems (which is R 1.7.1) here. It is a GNU project which is similar to the S language and environment which was developed at Bell Laboratories (formerly AT&T, now Lucent Technologies) by John Chambers and colleagues. R can be considered as a different implementation of S. There are some important differences, but much code written for S runs unaltered under R. Install useful R packages in RStudio. Download the file available at startuppackages.R. This is a text (script) file containing R commands that you will run. Double click on this downloaded file in your specified directory. This will open the file in RStudio. Step 1 – Installing R. There will be 3 versions listed, select the “Download the R for (Mac) OS X” version by first selecting the option below. This will take you to the binaries page. Download the R-3.2.3.pkg, which is the latest version as of this blog post. The package will download and double click to install.

Install Anaconda

What is Anaconda?

Anaconda free open source is distributing both Python and R programming language. Anaconda is widely used in the scientific community and data scientist to carry out Machine Learning project or data analysis.

Why use Anaconda?

Anaconda will help you to manage all the libraries required for Python, or R. Anaconda will install all the required libraries and IDE into one single folder to simplify package management. Otherwise, you would need to install them separately.

Mac User

Step 1) Go to https://www.anaconda.com/download/ and Download Anaconda for Python 3.6 for your OS.

By default, Chrome selects the downloading page of your system. In this tutorial, installation is done for Mac. If you run on Windows or Linux, download Anaconda 5.1 for Windows installer or Anaconda 5.1 for Linux installer.

Install Rstudio Mac

Step 2) You are now ready to install Anaconda. Double-click on the downloaded file to begin the installation. It is .dmg for mac and .exe for windows.You will be asked to confirm the installation. Click Continue button.

You are redirected to the Anaconda3 Installer.

Step 3) Next window displays the ReadMe. After you are done reading the document, click Continue

Install R Package For Mac

Step 4) This window shows the Anaconda End User License Agreement. Click Continue to agree.

Step 5) You are prompted to agree, click Agree to go to the next step.

Step 6) Click Change Install Location to set the location of Anaconda. By default, Anaconda is installed in the user environment: Users/YOURNAME/.

Select the destination by clicking on Install for me only. It means Anaconda will be accessible only to this user.

Step 7) You can install Anaconda now. Click Install to proceed. Anaconda takes around 2.5 GB on your hard drive.

A message box is prompt. You need to confirm by typing your password. Hit Install Software

The installation may take sometimes. It depends on your machine.

Step 8) Anaconda asks you if you want to install Microsoft VSCode. You can ignore it and hit Continue

Step 9) The installation is completed. You can close the window.

You are asked if you want to move 'Anaconda3' installer to the Trash. Click Move to Trash

You are done with the installation of Anaconda on a macOS system

Windows User

Step 1) Open the downloaded exe and click Next

Step 2) Accept the License Agreement

Step 3) Select Just Me and click Next

Step 4) Select Destination Folder and Click Next

Step 5) Click Install in next Screen

Step 6) Installation will begin

Once done, Anaconda will be installed.

Install R

Mac users

Step 1) Anaconda uses the terminal to install libraries. The terminal is a quick way to install libraries. We need to be sure to point the installation toward the right path. In our case, we set the location of Anaconda to the Users/USERNAME/. We can confirm this by checking anaconda3 folder.

Open Computer and select Users, USERNAME and anaconda3. It confirms that we installed Anaconda on the right path. Now, let's see how macOS write the path. Right-click, and then Get Info

Select the path Where and click Copy

Step 2) For Mac user:

  • The shortest way is to use the Spotlight Search and write terminal.

The terminal sets the default working directory to Users/USERNAME. As you can see in the figure below, the path of anaconda3 and the working directory are identical. In macOS, the latest folder is shown before the $. For me, it is Thomas. The terminal will install all the libraries in this working directory.

If the path on the text editor does not match the working directory, you can change it by writing cd PATH in the terminal. PATH is the path you pasted in the text editor. Don't forget to wrap the PATH with 'PATH'. This action will change the working directory to PATH.

Step 4) We are ready to install R. I recommend you to install all packages and dependencies with the conda command in the terminal.

r-essentials means conda will install R and all the necessary libraries used by data scientist.

Conda is downloading the libraries

It takes some time to upload all the libraries. Be patient..you are all set.

In the terminal, you should see Executing transaction: done. If so, you have successfully installed R.

You can check where R is located.

Windows User

Step 1) Open the Anaconda command prompt

Step 2) In the command prompt

  1. Enter the R install command
  2. Environment will be determined
  3. List of packages to be installed will be listed

Step 3) Enter y and hit the return key to start installation

Step 4) Installation will take time, and you will get done message.

Install Rstudio

Mac User

In the terminal, write the following code:

In the terminal, you should see Executing transaction: done. If so, you have successfully installed Rstudio.

You are all set now, congratulation!

Windows User

Step 1) Enter command to install R Studio in the Anaconda prompt

Step 2) You will be shown a list of packages that will be installed. Enter y

Express scribe for mac. Step 3) R Studio will be installed

Warning

Avoid as much as you can to install a library using pip for Python, and R. Conda libraries gather a lot of packages, you don't need to install libraries outside of conda environment.

Run Rstudio

Directly run the command line from the terminal to open Rstudio. You open the terminal and write rstudio. You can also use Desktop Shortcut

Or

A new window will be opened with Rstudio.

Test

Open Rstudio from the terminal and open a script. Write the following command:

  1. ## In Rstudio summary(cars)
  2. Click Run
  3. Check Output

If you can see the summary statistics, it works. You can close Rstudio without saving the files.

Install package

Install package with anaconda is trivial. You go to your favorite browser, type the name of the library followed by anaconda r.

You choose the link that points to anaconda. You copy and paste the library into the terminal.

For instance, we need to install randomForest for the tutorial on random forest; we go https://anaconda.org/r/r-randomforest.

Run conda install -c r r-randomforest --yes from the terminal.

The installation is completed.

Note that Thorough this tutorial, you won't need to install many libraries as the most used libraries came with the r-essential conda library. It includes ggplot for the graph and caret for the machine learning project.

Open a library

To run the R function randomForest(), we need to open the library containing the function. In the Rstudio script, we can write library(randomForest)

Warning: Avoid as much as possible to open unnecessary packages. You might ended up creating conflicts between libraries.

Run R code

We have two ways to run codes in R

  1. We can run the codes inside the Console. Our data will be stored in the Global Environment but no history is recorded. We won't be able to replicate the results once R is closed. We need to write the codes all over again. This method is not recommended if we want to replicate our save our codes
  1. Write the code in the script. We can write as many lines of codes as we want. To run the code, we simple select the rows we want to return. Finally, click on run. We can see the output in the Console. We can save our script and open it later. Our results won't we lost.

Warning: In we point the cursor at the second row (i.e., slice_vector[1:5]), the Console displays an error. That's, we didn't run the line number 1.

Similarly, if we point the cursor to an empty row and click on run, R return an empty output.

Reinstall from macOS Recovery

macOS Recovery makes it easy to reinstall the Mac operating system, even if you need to erase your startup disk first. All you need is a connection to the Internet. If a wireless network is available, you can choose it from the Wi-Fi menu in the menu bar. This menu is also available in macOS Recovery.

1. Start up from macOS Recovery

To start up from macOS Recovery, turn on your Mac and immediately press and hold one of the following combinations on your keyboard. Command-R is generally recommended, especially if your Mac was never upgraded to macOS Sierra 10.12.4 or later.

Command (⌘)-R

Reinstall the latest macOS that was installed on your Mac (recommended).

Option-⌘-R

Upgrade to the latest macOS that is compatible with your Mac.

Shift-Option-⌘-R

Reinstall the macOS that came with your Mac, or the closest version still available.

Release the keys when you see an Apple logo, spinning globe, or other startup screen.

You might be prompted to enter the login password of an administrator of this Mac, or your Apple ID password, or a firmware password. If so, enter the requested password to continue.

When you see the utilities window, you have started up from macOS Recovery.

2. Decide whether to erase (format) your disk

You probably don't need to erase, unless you're selling, trading in, or giving away your Mac, or you have an issue that requires you to erase. If you need to erase your disk before installing macOS, select Disk Utility from the Utilities window, then click Continue. Learn more about when and how to erase.

3. Install macOS

After starting up from macOS Recovery, choose Reinstall macOS (or Reinstall OS X) from the Utilities window. Then click Continue and follow the onscreen instructions to choose your disk and begin installation.

If the installer asks to unlock your disk, enter the password you use to log in to your Mac. If the installer doesn't see your disk, or it says that it can't install on your computer or volume, you might need to erase your disk.

Please allow installation to complete without putting your Mac to sleep or closing its lid. During installation, your Mac might restart and show a progress bar several times, and the screen might be empty for minutes at a time.

If your Mac restarts to a setup assistant, but you're selling it, trading it in, or giving it away, press Command-Q to quit the assistant without completing setup. Then click Shut Down. When the new owner starts up the Mac, they can use their own information to complete setup.

If you never upgraded to macOS Sierra 10.12.4 or later

If macOS Sierra 10.12.4 or later was never installed on your Mac, macOS Recovery works differently:

  • Command-R is still the recommended way to start up from macOS Recovery. This combination makes sure that the installation isn't associated with your Apple ID, which is important if you're selling or giving away your Mac.
  • Option-Command-R installs the macOS that came with your Mac, or the closest version still available.
  • Shift-Option-Command-R isn't available.

Learn more

mupn.netlify.com – 2018