# Chapter 2 Computing

This is not a book about R. It is however, a book that uses R. Because of this, you will need to be familiar with R. The text will point out some thing about R along the way, but some previous study of R is necessary.

The following (freely availible) readings are highly recommended:

• Hands-On Programming with R - Garrett Grolemund
• If you have never used R or RStudio before, Part 1, Chapters 1 - 3, will be useful.
• R for Data Science - Garrett Grolemund, Hadley Wickham
• This book helps getting you up to speed working with data in R. While it is a lot of reading, Chapters 1 - 21 are highly recommended.
• Part I, Chapters 1 - 8, of this book will help create a mental model for working with R. These chapters are not an easy read, so they should be returned to often. (Chapter 2 could be safely skipped for our purposes, but is important if you will use R in the long term.)

If you are a UIUC student who took the course STAT 420, the first six chapters of that book could serve as a nice refresher.

## 2.1 Resources

The following resources are more specific or more advanced, but could still prove to be useful.

## 2.2 BSL Idioms

Things here supercede everythign above.

### 2.2.2 BSL Style Overrides

• TODO: = instead of <-
• TODO: never use T or F, only TRUE or FALSE
FALSE == TRUE
## [1] FALSE
F     == TRUE
## [1] FALSE
F     =  TRUE
F     == TRUE
## [1] TRUE
• TODO: never ever ever use attach()
• TODO: never ever ever use <<-
• TODO: never ever ever use setwd() or set a working directory some other way
• TODO: a newline before and after any chunk
• TODO: use headers appropriately! (short names, good structure)
• TODO: never ever ever put spaces in filenames. use -. (others will use _.)
• TODO: load all needed packages at the beginning of an analysis in a single chunk (TODO: pros and cons of this approach)
• TODO: one plot per chunk! no other printed output

Be consistent…

• with yourself!
set.seed(1337);mu=10;sample_size=50;samples=100000;
x_bars=rep(0, samples)
for(i in 1:samples)
{
x_bars[i]=mean(rpois(sample_size,lambda = mu))}
x_bar_hist=hist(x_bars,breaks=50,main="Histogram of Sample Means",xlab="Sample Means",col="darkorange",border = "dodgerblue")
mean(x_bars>mu-2*sqrt(mu)/sqrt(sample_size)&x_bars<mu+2*sqrt(mu)/sqrt(sample_size))

### 2.2.3 Objects and Functions

To understand computations in R, two slogans are helpful:

• Everything that exists is an object.
• Everything tha thappens is a function call.

— John Chambers

• TODO: Functions + Objects
• these are the inputs and outputs of functions:
• functions
• vectors
• lists
• tibbles (dfs)

### 2.2.5 Help

• TODO: ?, google, stack overflow, (office hours, course forums)

### 2.2.6 Keyboard Shortcuts

• TODO: copy-paste, switch program, switch tab, etc…
• TODO: TAB!!!
• TODO: new chunk!
• TODO: style!
• TODO: keyboard shortcut for keyboard shortcut

## 2.3 Common Issues

• TODO: cannot find function called ""