Giter VIP home page Giter VIP logo

intro_to_r's Introduction

intro_to_r

A whistlestop tour of the R language and its capabilities

contents

  • How to install R

getting going

how to install R

  1. Install base r
pacaur -S r
  1. Run R in sudo you need sudo here as we're going to check what's been set up sudo R
  2. Check where R is going to install its packages Sys.getenv() R_LIBS_USER is where your packages go by default when you're not sudo, R_HOME is where they go when you are. This is important because there are a number of ways of installing packages in R, and not all of them allow you to specify where to put them! If you want to change any of these locations, then go ahead and just change these environment variables interactively or in your .rprofile file.

installing packages

There are a number of ways to install packages.

  • From interactive R, you can install open source packages stored on R's CRAN repository.
> R
> install.packages('devtools')
  • Using the additional devtools package, you can install from other sources (including github)
> devtools::install_github('kater-s/intro_to_r')
  • From the terminal, use R CMD INSTALL. This is useful if you want to script an install, or install from local (packages you have made).
R CMD INSTALL --help

If you want to follow this demo along, I'm using: R version 3.4.0 The following packages:

  • tidyverse (note one of the dependencies here requires gcc-fortran. Don't ask. Really, don't)
  • nycflights13
  • readr

what R can do

R started life as a stats language. Because it's pretty easy to get started, and because it contains a lot of pre-written statistical stuff, lots of statiticians use it. As their data requirements have grown, so have the capabilities of R. Some of these things are good, and some are not!

Useful things in R

using pre-installed sample data

If you want to try out some stats or even just get your hands on some numeric data, R has a lot of this pre-installed, or you can use external packages:

> data()
> library(nycflights13)
> library(dplyr)

> head(mtcars)
> head(diamonds)
> head(flights)

reading and writing to csv

You can also read in data from various files

library(readr)
read_csv("~/trainingMaterials/london.csv")
write_csv(mtcars, "~/trainingMaterials/mtcars.csv)

This just makes trying things out and learning stats really quick and easy. Happy face.

developing alongside the data

R allows you to be able to view the data that you have in memory as you're developing.

> mycars <- mtcars
> View(mycars)
> mtcars_refactored <- mutate(mtcars```

### stats
Understandably, R is really good for stats. Any methods you would ever want to use are there. Many also follow a convention:

> model_name(formula, data = data)
e.g.

lm(x ~ y, data = mydata)


## things I don't like about R

- a lot of the base packages (because they're old) are now not the best way of doing things (e.g. `plot` vs `ggplot`)
- a lot of code is littered with side-effects. This is OK, but people using these do not know about them (e.g. `acf`)
- most good programming practice isn't obvious/taught to noobs (even though it's easier)
- there are some new nifty things that I don't thing should be in R

### good programming practices
There are ways to write pretty good R code. I'll get on to how often people do this later, but they are there. These include things like:
- the reference class (RC) class system and environments
- function argument and return conventions (see the `tidyverse` for a lot of these)
- function argument assertions (`assert_that`, `assertive`, `checkmate`...)
- linting (`lintr`)
- test frameworks (`testthat`)
- test coverage statistics (`covr`)

intro_to_r's People

Watchers

James Cloos avatar Kate Ross-Smith avatar

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.