Giter Site home page Giter Site logo

dsc-installing-r-online-ds-pt-071519's Introduction

Installing R

Introduction

In this lesson we'll get R installed on your computer and begin to get you familiar with RStudio, a data science IDE that many useRs like to use!

Objectives

You will be able to:

  • Get R installed on your computer
  • Have RStudio installed on your computer
  • Change the color scheme of RStudio
  • Disable RStudio's default saving of .RData
  • Run your first RMarkdown script

Getting R

Over the course of the next few lessons we won't be running R in your browser, but rather putting it on your local machine.

This is unlike your previous learn.co work where you could run some of your code in the browser. For each of these lessons, you should git clone these repositories if you want to be able to run the code.

You might already have some software that could run R, but in order to make sure everything works for this series of lessons, please be sure to follow these steps exactly so everything works well!

This is especially true if you try to use the RStudio that comes along with Anaconda; it's best to just do a fresh install of both R and RStudio. Luckily R tends to be much easier to install and manage than Python.

So where do you get all things R?

The most up-to-date version of R can always be found on The Comprehensive R Archive Network or CRAN. If you navigate to https://cran.r-project.org/ you will see this page here:

r install image 1

Follow the links in the top box of Download and Install R to get R on your computer. The following series of screenshots will show what this process looks like if you're doing this as of May 2020 on an OSX system.

After you click Download R for (Mac) OS X, you should then see this image below:

r install image 2

If you then click on the where it says R-4.x.x.pkg, R will download on your computer.

r install image 3

You'll notice that R downloads pretty fast if you're on a decent internet connection. R 4.0.0 only requires about 170MB.

If you then open up the package that is downloaded (Chrome shown here), you can just follow the install instructions in the install wizard

r install image 4

r install image 5

You can verify that R has been installed by opening up your terminal and typing in R.

r install image 6

Try to type in something simple like:

2 + 2

into the console.

It will look something like this:

r install image 7

It works like a calculator just like Python!

To exit, type:

quit()

Then tell it n for no saying you don't want to save your work space!

Now unless you're some sort of masochist, you're never going to actually run R from your terminal for your data science projects. We need to get an IDE to help us out!

RStudio

Just like Python, there are many ways to interact with R as a programming language. One of the most popular choices at the moment, for reasons that will be made clear very soon, is RStudio. It can be a bit confusing when getting into the world of R because RStudio the IDE is created by RStudio PBC the company. As a fun fact, RStudio the company just announced that it is now a Public Benefit Corporation meaning that "corporate decisions must both align with this mission, as well as balance the interests of community, customers, employees, and shareholders". That's not super relevant to our install, but if you do talk to anyone in the R world, this was a very big deal. You can read more about it here.

So how do we get RStudio the IDE?

Let's navigate over to RStudio.com and again follow this set of install instructions.

r install image 8

Now if you're following these install instructions near May of 2020, you'll notice that RStudio's homepage is actually showing off a recent push that the company has been doing to have RStudio be able to run Python! You can read more about that here at this link.

But let's not get distracted!

If you go from the home page and hover over products you can get a link to find where to get RStudio

r install image 9

From here we want to get RStudio for desktop:

r install image 10

Clicking this will take you down the page to this next image where you actually get RStudio

r install image 11

We of course want the free, open source one!

It's important to notice that RStudio (the company) offers a lot of internal support for bigger data science teams.

r install image 12

And this takes you to where all the versions of RStudio live.

r install image 13

We can install RStudio with just dragging and dropping on OSX.

r install image 14

Once this has been installed with the drag and drop, we just double click to open up RStudio!

RStudio IDE

RStudio is the GUI for all things R. When you first open RStudio, typically you will see four separate panels.

r studio setup image 1

On the top left is your script editor where you write your code, on the bottom left you have your console where your code gets run. On the top right you see the environment-- something we'll talk about soon-- and then on the bottom right we see our Viewer. You can change the positions of this if you'd like and can find instructions to do that here and can also change the color schemes of your editor if you navigate to the preferences.

Let's first try that!

I'd like you to go in the top toolbar then select File > Preferences ....

r studio setup image 2

We can change here to Solarized Dark.

Now while we're here in Preferences, let's also do something that's going to save you a lot of pain in the long run which is make the default behavior to never save your work space.

r studio setup image 3

r studio setup image 4

Alright, let's now close this out and try to run something!

In order to do this, first close out RStudio so we can show you something cool.

Running a Script

Now we've done a lot here to get both R and RStudio installed and set up here, let's end with running one script!

First, clone this repo we're working out of to your local machine with the following commands.

git clone www.github.com/learn-co-curriculum/dsc-installing-r.git

Then cd into the directory and open the .rproj file in there.

cd dsc-installing-r
open dsc-installing-r.rproj

Doing this will open up another RStudio on your computer.

The .rproj file basically walls off the rest of your computer so RStudio thinks the entire universe of your project lives within this area. Using .rproj files helps eliminate absolute paths and makes it so it's a lot easier to get your R code to run on others computers. If you're serious about learning about good practices in working with R and RStudio, please check out this e-book here (written in R).

In this local repository for this lesson, you'll find a file called tips_report.Rmd that you should be able to see if you click the File tab on the bottom right quadrant of RStudio. This will open up your first RMarkdown file (the Juypter notebook of R).

This file contains the data and narrative we will be using the next lessons. We'll describe it more at the start of the next lesson!

With this open, let's just click where it says Knit at the top to see what happens.

Note here that because you've done a fresh install of R, you might be prompted to install a lot of software.

Make sure you agree to all of this!!.

The first time you run this, you will also see something like this which asks you if you want to install the library (or suite of libraries we're going to use) this time. Make sure to also install this and say Yes when it asks you at the command prompt to install everything!

r install warning

Typically we would do this at the command line with something like:

install.packages("tidyverse")

But RStudio is smart and realizes that we don't have it and we wanted to show you that!

Once all that software is installed, you should be able to run your script.

This will run the RMarkdown script and create a little report for you. Notice it's an HTML file of your analysis meaning you can now just put the file.html that was just created on any website! RMarkdown allows data scientists to make quick reports in HTML, LaTeX, or even Word formats.

We just wanted to show off this cool tool before working in R.

r faking seaborn

Summary

Go make yourself a coffee! You've just done a lot of good work. You've installed R, RStudio, and rendered your first RMarkdown file with RStudio.

In our next lesson, we'll actually type some more R code.

dsc-installing-r-online-ds-pt-071519's People

Contributors

davidjohnbaker1 avatar maxwellbenton avatar loredirick avatar cheffrey2000 avatar

Watchers

James Cloos avatar Kaitlin Vignali avatar Mohawk Greene avatar Victoria Thevenot avatar Bernard Mordan avatar Otha avatar raza jafri avatar  avatar Joe Cardarelli avatar The Learn Team avatar  avatar Ben Oren avatar Matt avatar Antoin avatar Alex Griffith avatar  avatar Amanda D'Avria avatar  avatar Ahmed avatar Nicole Kroese  avatar Dominique De León avatar  avatar Lisa Jiang avatar Vicki Aubin avatar  avatar  avatar

Forkers

leukamal

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.