Skip to content

Commit

Permalink
Many updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ndphillips committed Feb 21, 2017
1 parent 1631caf commit d2f8a0d
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 74 deletions.
21 changes: 0 additions & 21 deletions 01-intro.Rmd

This file was deleted.

3 changes: 0 additions & 3 deletions 02-literature.Rmd

This file was deleted.

3 changes: 0 additions & 3 deletions 03-method.Rmd

This file was deleted.

7 changes: 0 additions & 7 deletions 04-application.Rmd

This file was deleted.

3 changes: 0 additions & 3 deletions 05-summary.Rmd

This file was deleted.

1 change: 0 additions & 1 deletion 06-references.Rmd

This file was deleted.

2 changes: 1 addition & 1 deletion _bookdown.yml
@@ -1,4 +1,4 @@
book_filename: "bookdown-demo"
book_filename: "YaRrr"
language:
ui:
chapter_name: "Chapter "
4 changes: 2 additions & 2 deletions _output.yml
Expand Up @@ -10,7 +10,7 @@ bookdown::gitbook:
config:
toc:
before: |
<li><a href="./">A Minimal Book Example</a></li>
<li><a href="./">YaRrr! The Pirate's Guide to R</a></li>
after: |
<li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
edit: https://github.com/rstudio/bookdown-demo/edit/master/%s
edit: https://github.com/ndphillips/YaRrrBook/master/%s
18 changes: 0 additions & 18 deletions bookdown-demo.Rproj

This file was deleted.

108 changes: 93 additions & 15 deletions index.Rmd
@@ -1,6 +1,6 @@
---
title: "A Minimal Book Example"
author: "Yihui Xie"
title: "YaRrr! The Pirate's Guide to R"
author: "Nathaniel D. Phillips"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
output: bookdown::gitbook
Expand All @@ -9,26 +9,104 @@ bibliography: [book.bib, packages.bib]
biblio-style: apalike
link-citations: yes
github-repo: rstudio/bookdown-demo
description: "This is a minimal example of using the bookdown package to write a book. The output format for this example is bookdown::gitbook."
description: "An introductory book to R written by, and for, R pirates"
cover-image: images/YaRrr_Cover.jpg
url: 'https\://bookdown.org/ndphillips/YaRrr/'
---

# Prerequisites
# Preface {#intro}

This is a _sample_ book written in **Markdown**. You can use anything that Pandoc's Markdown supports, e.g., a math equation $a^2 + b^2 = c^2$.
```{r fig.align='center', echo=FALSE, out.width = "600px"}
knitr::include_graphics('images/YaRrr_Cover.jpg')
```

The purpose of this book is to help you learn R from the ground-up.

## Where did this book come from?

Let me make something very, very clear...

*I did not write this book*.

This whole story started in the Summer of 2015. I was taking a late night swim on the Bodensee in Konstanz and saw a rusty object sticking out of the water. Upon digging it out, I realized it was an ancient usb-stick with the word YaRrr inscribed on the side. Intrigued, I brought it home and plugged it into my laptop. Inside the stick, I found a single pdf file written entirely in pirate-speak. After watching several pirate movies, I learned enough pirate-speak to begin translating the text to English. Sure enough, the book turned out to be an introduction to R called The Pirate's Guide to R.

This book clearly has both massive historical and pedagogical significance. Most importantly, it turns out that pirates were programming in R well before the earliest known advent of computers. Of slightly less significance is that the book has turned out to be a surprisingly up-to-date and approachable introductory text to R. For both of these reasons, I felt it was my duty to share the book with the world.

If you or spot any typos or errors, or have any recommendations for future versions of the book, please write me at YaRrr.Book\@gmail.com or tweet me \@YaRrrBook.

## Who is this book for?

While this book was originally written for pirates, I think that anyone who wants to learn R can benefit from this book. If you haven't had an introductory course in statistics, some of the later statistical concepts may be difficult, but I'll try my best to add brief descriptions of new topics when necessary. Likewise, if R is your first programming language, you'll likely find the first few chapters quite challenging as you learn the basics of programming. However, if R is your first programming language, that's totally fine as what you learn here will help you in learning other languages as well (if you choose to). Finally, while the techniques in this book apply to most data analysis problems, because my background is in experimental psychology I will cater the course to solving analysis problems commonly faced in psychological research.

**What this book is**

For now, you have to install the development versions of **bookdown** from Github:
This book is meant to introduce you to the basic analytical tools in R, from basic coding and analyses, to data wrangling, plotting, and statistical inference.

```{r eval=FALSE}
devtools::install_github("rstudio/bookdown")
**What this book is not**

This book does not cover any one topic in extensive detail. If you are interested in conducting analyses or creating plots not covered in the book, I'm sure you'll find the answer with a quick Google search!

## Why is R so great?

As you've already gotten this book, you probably already have some idea why R is so great. However, in order to help prevent you from giving up the first time you run into a programming wall, let me give you a few more reasons:

1. R is 100\% free and as a result, has a huge support community. Unlike SPSS, Matlab, Excel and JMP, R is, and always will be completely free. This doesn't just help your wallet - it means that a huge community of R programmers will constantly develop an distribute new R functionality and packages at a speed that leaves all those other packages in the dust! Unlike Fight Club, the first rule of R is "Do talk about R!" The size of the R programming community is staggering. If you ever have a question about how to implement something in R, a quick Poogle\footnote{I am in the process of creating Poogle - Google for Pirates. Kickstarter page coming soon...} search will lead you to your answer virtually every single time.

2. R is the presnt, and future of statistical programming. To illustrate this, look at the following three figures. These are Google trend searches for three terms: R Programming, Matlab, and SPSS. Try and guess which one is which.

```{r, echo = FALSE}
knitr::include_graphics("images/googletrends.png")
```

Remember each Rmd file contains one and only one chapter, and a chapter is defined by the first-level heading `#`.
3. R is incredibly versatile. You can use R to do everything from calculating simple summary statistics, to performing complex simulations to creating gorgeous plots like the chord diagram on the right. If you can imagine an analytical task, you can almost certainly implement it in R.

To compile this example to PDF, you need to install XeLaTeX.
4. Using RStudio, a program to help you write R code, You can easily and seamlessly combine R code, analyses, plots, and written text into elegant documents all in one place using Sweave (R and Latex) or RMarkdown. In fact, I translated this entire book (the text, formatting, plots, code...yes, everything) in RStudio using Sweave. With RStudio and Sweave, instead of trying to manage two or three programs, say Excel, Word and (sigh) SPSS, where you find yourself spending half your time copying, pasting and formatting data, images and test, you can do everything in one place so nothing gets misread, mistyped, or forgotten.

```{r include=FALSE}
# automatically create a bib database for R packages
knitr::write_bib(c(
.packages(), 'bookdown', 'knitr', 'rmarkdown'
), 'packages.bib')
```{r, fig.cap = "A super cool chord diagram from the circlize package"}
circlize::chordDiagram(matrix(sample(10),
nrow = 2, ncol = 5))
```


5. Analyses conducted in R are transparent, easily shareable, and reproducible. If you ask an SPSS user how they conducted a specific analyses, they will either A) Not remember, B) Try (nervously) to construct an analysis procedure on the spot that makes sense - which may or may not correspond to what they actually did months or years ago, or C) Ask you what you are doing in their house. I used to primarily use SPSS, so I speak from experience on this. If you ask an R user (who uses good programming techniques!) how they conducted an analysis, they should always be able to show you the exact code they used. Of course, this doesn't mean that they used the appropriate analysis or interpreted it correctly, but with all the original code, any problems should be completely transparent!

6. And most importantly of all, R is the programming language of choice for pirates.



## R is like a relationship...

Yes, R is very much like a relationship. Like relationships, there are two major truths to R programming:

```{r, echo = FALSE, fig.cap = "Yep, R will become both your best friend and your worst nightmare. The bad times will make the good times oh so much sweeter.", fig.align='center'}
knitr::include_graphics("images/rrelationship.png")
```

1. There is nothing more *frustrating* than when your code does *not* work

2. There is nothing more *satisfying* than when your code *does* work!


Anything worth doing, from losing weight to getting a degree, takes time. Learning R is no different. Especially if this is your first experience programming, you are going to experience a *lot* of headaches when you get started. You will run into error after error and pound your fists against the table screaming: "WHY ISN'T MY CODE WORKING?!?!? There must be something wrong with this stupid software!!!" You will spend hours trying to find a bug in your code, only to find that - frustratingly enough, you had had an extra space or missed a comma somewhere. You'll then wonder why you ever decided to learn R when (::sigh::) SPSS was so "nice and easy."


```{r, echo = FALSE, fig.cap = "When you first meet R, it will look so fugly that you'll wonder if this is all some kind of sick joke. But trust me, once you learn how to talk to it, and clean it up a bit, all your friends will be crazy jealous.", fig.align='center'}
knitr::include_graphics("images/gosling.png")
```

**Fun Fact!** SPSS stands for "Shitty Piece of Shitty Shit". True story.

This is perfectly normal! Don't get discouraged and DON'T GO BACK TO SPSS! That would be quitting on exercise altogether because you had a tough workout.

Trust me, as you gain more programming experience, you'll experience fewer and fewer bugs (though they'll never go away completely). Once you get over the initial barriers, you'll find yourself conducting analyses much, much faster than you ever did before.


## Who am I?

```{r, fig.cap= "Like a pirate, I work best with a mug of beer within arms' reach.", fig.margin = TRUE, echo = FALSE, fig.align='center'}
knitr::include_graphics("images/beer.jpg")
```

My name is Nathaniel -- not Nathan...not Nate...and *definitely* not Nat. I am a psychologist with a background in statistics and judgment and decision making. You can find my R (and non-R) related musings at [http://ndphillips.github.io](http://ndphillips.github.io)


3 changes: 3 additions & 0 deletions style.css
Expand Up @@ -12,3 +12,6 @@ pre {
pre code {
white-space: inherit;
}
.error {
color: red;
}

0 comments on commit d2f8a0d

Please sign in to comment.