-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathrsetup.Rmd
154 lines (117 loc) · 5.02 KB
/
rsetup.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
% Setting Up R
% DPI R Bootcamp Dec. 3rd to 5th, 2012
% Jared Knowles
# Getting Ready for the DPI R Bootcamp
- How to get up and running with R in no time!
<p align="center"><img src="img/dpilogo.png" height="81" width="138"></p>
# Materials
- [Download R](http://cran.r-project.org/)
- [RStudio](http://www.rstudio.org/)
- We'll also want to install a few basic packages. This can be done on the fly later, but a few include `ggplot2`;`knitr`;`plyr`
# Step 1: Install R
- Simply run the installer. If you have a 64-bit machine, choose 64 bit R, if you don't know, just choose the default
- The install should be less than 100mb
- There is a short video on the next slide for help installing on Windows machines
# Installing R on Windows
<p align='center'><iframe src="http://www.screenr.com/embed/kzT8" width="650" height="396" frameborder="0"></iframe></p>
# Installing R on a Mac
- Get the install file from [CRAN](http://cran.r-project.org/bin/macosx/)
- Get [RStudio](http://www.rstudio.org/)
- Run the R installer, and then run the RStudio installer
# Installing R on Ubuntu or Debian Linux
- Read the [install notes online](http://cran.r-project.org/bin/linux/ubuntu/README)
- Get [RStudio](http://www.rstudio.org/)
- Run the R installer, and then run the RStudio installer
# Step 2: RStudio
- Now run the RStudio installer
- RStudio will automatically find your R installation
# Step 3: Install packages
First, watch this tutorial<br>
<p align='center'><iframe src="http://www.screenr.com/embed/Fps8" width="650" height="396" frameborder="0"></iframe></p>
# Install Packages
- Are you running RStudio in administrator mode on Windows Vista or Windows 7?
- If not, you need to be to install packages (in most cases)
- When you launch RStudio, right click on the icon for RStudio and then click "Run as Administrator"
- If you are on a Mac or Windows XP you can disregard this
# Install Packages (2)
- Now, copy and paste the code below into the bottom left window in RStudio (the R terminal):
```{r, eval=FALSE,echo=TRUE,tidy=FALSE}
install_new<-function(mypkg){
if (mypkg %in% installed.packages()) cat("Package already installed")
else{cat("Package not found, so installing with dependencies...\n
Press CTRL C to abort.")
Sys.sleep(5)
install.packages(mypkg,repos="http://cran.wustl.edu/")
}
}
install_new('plyr')
install_new('lmtest')
install_new('ggplot2')
install_new('gridExtra')
install_new('eeptools')
install_new('stringr')
install_new('knitr')
install_new('quantreg')
install_new('xtable')
install_new('lme4')
install_new('caret')
```
# Alternate Install
- If you want or if you have troubles with the above, you can overwrite any existing versions of those packages and do the install in one line, shown below:
```{r eval=FALSE,echo=TRUE,tidy=FALSE}
install.packages(c('plyr','lmtest','ggplot2','gridExtra','stringr',
'knitr','quantreg','xtable','lme4','eeptools','caret'),
repos="http://cran.wustl.edu/")
```
# Run RStudio
- You should be able to run RStudio now and load any of the packages above.
- Run the code below in the RStudio terminal panel (bottom left) to test this:
```{r eval=FALSE,echo=TRUE}
library(lmtest)
example(gqtest)
```
# And you should see...
```{r eval=TRUE,echo=FALSE}
library(lmtest)
example(gqtest)
```
# And test the graphics...
Type in in the terminal (or copy and paste)
```{r echo=TRUE,eval=FALSE}
library(ggplot2)
y<-rt(200,df=5)
qplot(sample=y,stat="qq")
```
# Results
```{r,echo=TRUE,fig.width=9,fig.height=6}
library(ggplot2)
y<-rt(200,df=5)
qplot(sample=y,stat="qq")
```
# That's all
- Did you see the output like the slides above?
- Did you see the plot in the lower right?
# Optional
- If you want to see the cutting edge of R development--interactive web-based data applications, you can install the following beta software
```{r,echo=TRUE,eval=FALSE}
options(repos=c(RStudio='http://rstudio.org/_packages', getOption('repos')))
install.packages('shiny')
```
# Optional Cont.
- To check if it worked (and it might not depending on your machine's configuration)
```{r echo=TRUE,eval=FALSE}
library(shiny)
runExample("06_tabsets")
```
- Does a new browser window or tab open up?
- In RStudio hit the "stop" button in the terminal panel to exit the demo
# You are ready to go!
See you on December 3rd to the 5th to find out how to go from these basic steps to using R to learn from your data.
Can't wait to see you in Madison!
# Attribution and License
This work (<span property="dct:title">R Tutorial for Education</span>, by <a href="www.jaredknowles.com" rel="dct:creator"><span property="dct:title">Jared E. Knowles</span></a>), in service of the <a href="http://www.dpi.wi.gov" rel="dct:publisher"><span property="dct:title">Wisconsin Department of Public Instruction</span></a>, is free of known copyright restrictions.
</p>
<p xmlns:dct="http://purl.org/dc/terms/">
<a rel="license" href="http://creativecommons.org/publicdomain/mark/1.0/">
<img src="http://i.creativecommons.org/p/mark/1.0/88x31.png" style="border-style: none;" alt="Public Domain Mark" /> </a>
<br />