# 21 R programming

## 21.1 Best Coding Practices for R

R is a huge language and I would like to share the little knowledge I have in the subject. I don’t claim to be an expert but this book will guide you in the right path wherever possible.

Most of the books about R programming language will tell you what are the possible ways to do one thing in R. This book will only tell you one way to do that thing correctly.

https://bookdown.org/content/d1e53ac9-28ce-472f-bc2c-f499f18264a3/

## 21.2 Modern R with the tidyverse

Bruno Rodrigues

This book can be useful to different audiences. If you have never used R in your life, and want to start, start with Chapter 1 of this book. Chapter 1 to 3 are the very basics, and should be easy to follow up to Chapter 9. Starting with Chapter 9, it gets more technical, and will be harder to follow. But I suggest you keep on going, and do not hesitate to contact me for help if you struggle! Chapter 9 is also where you can start if you are already familiar with R and the {tidyverse}, but not functional programming. If you are familiar with R but not the {tidyverse} (or have no clue what the {tidyverse} is), then you can start with Chapter 4. If you are familiar with R, the {tidyverse} and functional programming, you might still be interested in this book, especially Chapter 9 and 10, which deal with package development and further advanced topics respectively.

## 21.3 stats545 Data wrangling, exploration, and analysis with R

Jenny Bryan

Learn how to:

Explore, groom, visualize, and analyze data, make all of that reproducible, reusable, and shareable, using R. This site is about everything that comes up during data analysis except for statistical modelling and inference.

## 21.4 What They Forgot to Teach You About R

Jennifer Bryan and Jim Hester

The initial impetus for creating these materials is a two-day hands-on workshop. The target learner:

Has a moderate amount of R and RStudio experience.Is largely self-taught.Suspects they have drifted into some idiosyncratic habits that may slow them down or make their work products more brittle.Is interested in (re)designing their R lifestyle, to be more effective and more self-sufficient.

## 21.5 Field Guide to the R Ecosystem

Mark Sellors

This field guide aims to introduce the reader to the main components of the R ecosystem that may be encountered in “the field”.Whatever the reason, whilst there is a wealth of in-depth information for people actually using the language, I could find precious little information that provided the sort of overview of the ecosystem that I know I’d have appreciated when I first came to the language. And with that thought, a field guide is born…

## 21.6 Functional Programming

Sara Altman, Bill Behrman, Hadley Wickham

This book is a practical introduction to functional programming using the tidyverse.

## 21.7 YaRrr! The Pirate’s Guide to R

Nathaniel D. Phillips

Learn R from the ground up.

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.

## 21.8 Advanced R

This is the companion website for “Advanced R”, a book in Chapman & Hall’s R Series. The book is designed primarily for R users who want to improve their programming skills and understanding of the language. It should also be useful for programmers coming to R from other languages, as it explains some of R’s quirks and shows how some parts that seem horrible do have a positive side.

The book is free online. (Ignore the message redirecting you to the 2nd edition, this is the latest edition)

and the solutions can be found here: https://advanced-r-solutions.rbind.io/

## 21.9 Advanced R Solutions

Malte Grosser, Henning Bumann & Hadley Wickham

This book offers solutions to the exercises from Hadley Wickham’s book Advanced R (Edition 2). It is work in progress and under active development. The 2nd edition of Advanced R has been published and we are currently working towards completion.

## 21.10 Efficient R programming

Colin Gillespie and Robin Lovelace

This book is for anyone who wants to make their R code faster to type, faster to run and more scalable. These considerations generally come after learning the very basics of R for data analysis.

The book is free online.

## 21.11 The Tidyverse Cookbook

Edited by Garrett Grolemund

This book collects code recipes for doing data science with R’s tidyverse. Each recipe solves a single common task, with a minimum of discussion.

## 21.12 The tidyverse style guide

Good coding style is like correct punctuation: you can manage without it, butitsuremakesthingseasiertoread. This site describes the style used throughout the tidyverse. It was derived from Google’s original R Style Guide - but Google’s current guide is derived from the tidyverse style guide.

## 21.13 Tidyverse design guide

Tidyverse team

The goal of this book is to help you write better R code. It has four main components:

Design problems which lead to suboptimal outcomes.

Useful patterns that help solve common problems.

Key principles that help you balance conflicting patterns.

Selected case studies that help you see how all the pieces fit together with real code.

It is used by the tidyverse team to promote consistency across packages in the core tidyverse.

## 21.14 Tidyverse Skills for Data Science

Carrie Wright, Shannon E. Ellis, Stephanie C. Hicks and Roger D. Peng

Book and Course formats

This course introduces a powerful set of data science tools known as the Tidyverse. The Tidyverse has revolutionized the way in which data scientists do almost every aspect of their job. We will cover the simple idea of “tidy data” and how this idea serves to organize data for analysis and modeling. We will also cover how non-tidy data can be transformed to tidy data, the data science project life cycle, and the ecosystem of Tidyverse R packages that can be used to execute a data science project.

Book format https://jhudatascience.org/tidyversecourse/

Ebook: https://leanpub.com/tidyverseskillsdatascience

Course format https://www.coursera.org/specializations/tidyverse-data-science-r

## 21.15 Hands-On Programming with R

Garrett Grolemund

This book will teach you how to program in R, with hands-on examples. I wrote it for non-programmers to provide a friendly introduction to the R language. You’ll learn how to load data, assemble and disassemble data objects, navigate R’s environment system, write your own functions, and use all of R’s programming tools. Throughout the book, you’ll use your newfound skills to solve practical data science problems.

## 21.16 R for Excel users

Julie Lowndes & Allison Horst

This course is for Excel users who want to add or integrate R and RStudio into their existing data analysis toolkit. It is a friendly intro to becoming a modern R user, full of tidyverse, RMarkdown, GitHub, collaboration & reproducibility.

## 21.17 The R Language

A collection of manuals: 1. An Introduction to R 1. The R Language Definition 1. Writing R Extensions 1. R Installation and Administration 1. R Data Import/Export 1. R Internals

## 21.18 R for Graduate Students

Y. Wendy Huynh

Hello! My name is Wendy Huynh and I am a current PhD student working in the behavioral neurosciences. I began my R journey at the end of my first year of graduate school, slowly and painfully piecing together code. Although programming was never really part of my program, I now see it as an integral part of my work.

Many fellow graduate students expressed interest in learning R, but didn’t know where to begin. Programming with R is still relatively niche among my cohort and there are very few formal classes teaching this subject.

Although there are many amazing guides/textbooks for R out there, very few of them featured examples relevant for my specific needs and were user-friendly enough for a true beginner. In the Fall of my second year, I began teaching a new graduate student in my lab everything I knew about R. However, I quickly found that teaching R – even just to one person – was very time consuming. I decided to write up assignments as a “short” guide to R. After writing a short 11 page “first assignment” and receiving positive feedback, I began writing up a second assignment. Then a third. Soon enough, I had written enough pages that I couldn’t deny that this “short guide” had turned into a book.

## 21.19 R language for programmers

I have written software professionally in perhaps a dozen programming languages, and the hardest language for me to learn has been R. The language is actually fairly simple, but it is unconventional. These notes are intended to make the language easier to learn for someone used to more commonly used languages such as C++, Java, Perl, etc.

## 21.20 R Cookbook - 2nd edition

JD Long, Paul Teetor

I have written software professionally in perhaps a dozen programming languages, and the hardest language for me to learn has been R. The language is actually fairly simple, but it is unconventional. These notes are intended to make the language easier to learn for someone used to more commonly used languages such as C++, Java, Perl, etc.

Not to be confused with Cookbook for R https://rc2e.com/index.html

## 21.21 Cookbook for R

Winston Chang

The goal of the cookbook is to provide solutions to common tasks and problems in analyzing data.

Not to be confused with R Cookbook http://www.cookbook-r.com/

## 21.22 Tidy evaluation

Lionel Henry and Hadley Wickham

This guide is now superseded by more recent efforts at documenting tidy evaluation in a user-friendly way. We now recommend reading:

The new Programming with dplyr vignette.

The Using ggplot2 in packages vignette.

(Oscar’s note: I’m keeping this in for my own reference)

## 21.23 Rcpp for everyone

*Masaki E. Tsuda*

Rcpp is a package that enables you to implement R functions in C++. It is easy to use even without deep knowledge of C++, because it is implemented so as to write your C++ code in a style similar to R. And Rcpp does not sacrifice execution speed for the ease of use, anyone can get high performance outcome.

This document focuses on providing necessary information to users who are not familiar with C++. Therefore, in some cases, I explain usage of Rcpp conceptually rather than describing accurately from the viewpoint of C++, so that I hope readers can easily understand it.

## 21.24 The R Inferno

Patrick Burns

If R’s behaviour has ever suprised you, then this book is a guide for many more surprises, written in the style of Dante. It’s a concise report on number of common-errors and unexpected behaviours in R. This book would make more sense, if you have been programming and are familiar with such behaviours (not all though), as there is little time spent on explaining why part of behaviour. As mentioned, it’s a concise book, 126 pages only.

## 21.25 A sufficient Introduction to R

Derek l. Sonderegger

This book is intended to guide people that are completely new to programming along a path towards a useful skill level using R. I belive that while people can get by with just copying code chunks, that doesn’t give them the background information to modify the code in non-trivial ways. Therefore we will spend more time on foundational details than a “crash-course” would.

## 21.26 Introduction to Programming with R

Reto Stauffer, Joanna Chimiak-Opoka, Thorsten Simon, Achim Zeileis

a learning resource for programming novices who want to learn programming using the statistical programming language R. While one of the major strengths of R is the broad variety of packages for statistics and data science, this resource focuses on learning and understanding basic programming concepts using base R. Only a couple of additional packages are used and/or briefly discussed for special tasks.

This online book is specifically written for participants of the course “Introduction to Programming: Programming in R” offered by the Digital Science Center at Universität Innsbruck.

## 21.27 Mastering Software Development in R

Roger D. Peng, Sean Kross, and Brooke Anderson

This book covers R software development for building data science tools. This book provides rigorous training in the R language and covers modern software development practices for building tools that are highly reusable, modular, and suitable for use in a team-based environment or a community of developers.

Pay what you want for the ebook, minimum $0.00

## 21.28 Introduction to R - R spatial

R Spatial

This document provides a concise introduction to R. It emphasizes what you need to know to be able to use the language in any context. There is no fancy statistical analysis here. We just present the basics of the R language itself. We do not assume that you have done any computer programming before (but we do assume that you think it is about time you did). Experienced R users obviously need not read this. But the material may be useful if you want to refresh your memory, if you have not used R much, or if you feel confused.

## 21.29 Another Book on Data Science : Learn R and Python in Parallel

Nailong Zhang

There has been considerable debate over choosing R vs. Python for Data Science. Based on my limited knowledge/experience, both R and Python are great languages and are worth learning; so why not learn them together?

Besides the side-by-side comparison of the two popular languages used in Data Science, this book also focuses on the translation from mathematical models to codes. In the book, the audience could find the applications/implementations of some important algorithms from scratch, such as maximum likelihood estimation, inversion sampling, copula simulation, simulated annealing, bootstrapping, linear regression (lasso/ridge regression), logistic regression, gradient boosting trees, etc.

## 21.30 Functional Programming in R

Master functions and discover how to write functional programs in R. In this concise book, you’ll make your functions pure by avoiding side-effects; you’ll write functions that manipulate other functions, and you’ll construct complex functions using simpler functions as building blocks.

## 21.31 Advanced Object-Oriented Programming in R

Learn how to write object-oriented programs in R and how to construct classes and class hierarchies in the three object-oriented systems available in R. This book gives an introduction to object-oriented programming in the R programming language and shows you how to use and apply R in an object-oriented manner. You will then be able to use this powerful programming style in your own statistical programming projects to write flexible and extendable software.

Paid ~$20

## 21.32 Metaprogramming in R

Learn how to manipulate functions and expressions to modify how the R language interprets itself. This book is an introduction to metaprogramming in the R language, so you will write programs to manipulate other programs. Metaprogramming in R shows you how to treat code as data that you can generate, analyze, or modify.

Paid ~$20

## 21.33 Functional Data Structures in R

Get an introduction to functional data structures using R and write more effective code and gain performance for your programs. This book teaches you workarounds because data in functional languages is not mutable: for example you’ll learn how to change variable-value bindings by modifying environments, which can be exploited to emulate pointers and implement traditional data structures. You’ll also see how, by abandoning traditional data structures, you can manipulate structures by building new versions rather than modifying them. You’ll discover how these so-called functional data structures are different from the traditional data structures you might know, but are worth understanding to do serious algorithmic programming in a functional language such as R.

Paid~ $20

## 21.34 Domain-Specific Languages in R

Gain an accelerated introduction to domain-specific languages in R, including coverage of regular expressions. This compact, in-depth book shows you how DSLs are programming languages specialized for a particular purpose, as opposed to general purpose programming languages. Along the way, you’ll learn to specify tasks you want to do in a precise way and achieve programming goals within a domain-specific context.

Domain-Specific Languages in R includes examples of DSLs including large data sets or matrix multiplication; pattern matching DSLs for application in computer vision; and DSLs for continuous time Markov chains and their applications in data science. After reading and using this book, you’ll understand how to write DSLs in R and have skills you can extrapolate to other programming languages.

Paid ~$25

## 21.35 An Introduction to R

Alex Douglas, Deon Roos, Ana Couto, Francesca Mancini and David Lusseau

The aim of this book is to introduce you to using R, a powerful and flexible interactive environment for statistical computing and research. R in itself is not difficult to learn, but as with learning any new language (spoken or computer) the initial learning curve can be a little steep and somewhat daunting. We have tried to simplify the content of this book as much as possible and have based it on our own personal experience of teaching (and learning) R over the last 15 years. It is not intended to cover everything there is to know about R - that would be an impossible task. Neither is it intended to be an introductory statistics course, although you will be using some simple statistics to highlight some of R’s capabilities. The main aim of this book is to help you climb the initial learning curve and provide you with the basic skills and experience (and confidence!) to enable you to further your experience in using R.

## 21.36 An Introduction to Data Analysis

This book provides basic reading material for an introduction to data analysis. It uses R to handle, plot and analyze data. After covering the use of R for data wrangling and plotting, the book introduces key concepts of data analysis from a Bayesian and a frequentist tradition. This text is intended for use as a first introduction to statistics for an audience with some affinity towards programming, but no prior exposition to R.

https://michael-franke.github.io/intro-data-analysis/index.html