Why Rstudio is great?

Jon Duan
Nov. 14 2015

Reproducible Research

http://ateucher.github.io/rcourse_site/basics.html https://github.com/ateucher/rcourse_site

  • knitr
    • easy to produce documents: html(Rpubs), PDF, Word: assignment, project report.
    • easy to write formula $$.
    • easy to include results.
  • ggplot2
    • Best graph tool
  • dplyr
    • Strong tool for data process

R basic

http://ateucher.github.io/rcourse_site/basics.html

  • Introduction to R and RStudio
  • Calculations
  • A note about naming things
  • Functions
    • Specifying arguments
  • Help
  • Navigating your environment
  • Workspace

Data types and structures

Understanding basic data types in R

R has 6 (although we will not discuss the raw class for this workshop) data types.

  • character: "a", "swc"
  • numeric: 2, 15.5
  • integer: 2L (the L tells R to store this as an integer)
  • logical: TRUE, FALSE
  • complex: 1+4i (complex numbers with real and imaginary parts)

Basic data structures in R

R has many data structures. The main ones are:

  • vector
  • list
  • matrix
  • data frame
  • factors

Knitr

Slide With Code2

Slide With Chunk

Other options you can add to the tag

http://rmarkdown.rstudio.com/authoring_rcodechunks.html

Option Description
echo = TRUE or FALSE to show or hide code.
eval = TRUE or FALSE to run or skip the code.
warning = TRUE or FALSE to show or hide function warnings.
message = TRUE or FALSE to show or hide function R messages.
results = “hide” will hide results. They will still be executed
fig.height = Height of figure
fig.width = width of figure

Slide With Python

x = 'hello, python world!'
print(x.split(' '))
['hello,', 'python', 'world!']

Slide With c

library(knitr)
opts_chunk$set(cache = TRUE) 
#include <Rcpp.h>

// [[Rcpp::export]]
int fibonacci(const int x) {
    if (x == 0 || x == 1) return(x);
    return (fibonacci(x - 1)) + fibonacci(x - 2);
}

software-carpentry: best place to start

Slide With Literate Programming

RStudio and IPython Notebook,

Individual documents are easily placed under version control and shared with colleagues via email, GitHub, or online hosting services like RPubs and IPyNb Viewer.

The default notebook presentation style is to show the code cells with the numbered In []: and Out []: block numbering, but it presumably only takes a small style extension or customisation to suppress that? And another small extension to add the ability to hide a code cell and just display the output?