Site icon R-bloggers

Review of ‘Advanced R’ by Hadley Wickham

[This article was first published on Burns Statistics » R language, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Executive summary

Surprisingly good.

And it’s not like my expectations were especially low.

Structure

There are 20 chapters.  I mostly like the chapters and their order.

Hadley breaks the 20 chapters into 4 parts.  He’s wrong.  Figure 1 illustrates the correct way to formulate parts.

Figure 1: Chapters and Parts of Advanced R. 

 

Introductory R

There are by now lots of introductions to R.  There’s even an R for Dummies.

The introduction here is clean and serviceable.  If you are an experienced programmer learning R, these chapters will provide you with most of the basics.

Interlude

Chapter 5 on code style is a bit of fluff that insulates the introductory material from the more advanced part.  I hope most people can just about cope with there being an extra space or new line compared to their preference.

However, the chapter does talk about one thing that I think is very important: consistent naming style.  Consistent naming conserves a lot of energy for users — it allows them to think about what they are doing rather than trying to remember trivia.  I believe my personal best for continuous consistent naming in R is 4.3 hours of coding time.  In R it’s hard.

Language R

In which the balance of the universe is partially restored.

There are lots of places that talk about what a chaotic mess R is.  A book-length dose of venom is The R Inferno.

These chapters, in contrast, show the elegance, the flexibility, the power of the R language.  This is the mesmerizing part of the book.

Both views are valid: the mess in on the surface, the beauty is deeper.

Working with R

Useful.  But it includes the word “work” so it can’t be all good.

Favorite sentences

R doesn’t protect you from yourself: you can easily shoot yourself in the foot.  As long as you don’t aim the gun at your foot and pull the trigger, you won’t have a problem.

On speed:

R was purposely designed to make data analysis and statistics easier for you to do.  It was not designed to make life easier for your computer.  While R is slow compared to other programming languages, for most purposes, it’s fast enough.

On object orientation:

S3 is informal and ad hoc, but it has a certain elegance in its minimalism: you can’t take away any part of it and still have a useful OO system.

 

Appendix R

Here is the code that created Figure 1:

P.advanced_R_table_of_contents <- 
 function (filename = "advanced_R_table_of_contents.png", seed=18) 
{
  if(length(filename)) {
    png(file=filename, width=512, height=700)
    par(mar=rep(0,4)+.1)
  }
  advR.chap <- c('Introduction', 'Data structures', 'Subsetting', 'Vocabulary',
                 'Style guide', 'Functions', 'OO field guide', 'Environments', 
                 'Debugging, condition handling, and defensive programming', 
                 'Functional programming', 'Functionals', 'Function operators',
                 'Non-standard evaluation', 'Expressions', 'Domain specific languages',
                 'Performance', 'Optimising code', 'Memory', 
                 'High performance functions with Rcpp', "R's C interface")
  advR.chap[9] <- "Debugging, [...]"
  plot.new()
  plot.window(xlim=c(0,4), ylim=c(21,0))
  hl <- 1.7
  pl <- 2.3
 
  if(length(seed) && !is.na(seed)) set.seed(seed)

  text(c(.5, 2, 3.5), .5, c("Hadley part", "Chapter", "Pat part"), =2)
  rect(0, 1.5, hl, 9.5, col=do.call('rgb', as.list(runif(3, .8, 1))), border=NA)
  rect(0, 9.5, hl, 12.5, col=do.call('rgb', as.list(runif(3, .8, 1))), border=NA)
  rect(0, 12.5, hl, 15.5, col=do.call('rgb', as.list(runif(3, .8, 1))), border=NA)
  rect(0, 15.5, hl, 20.5, col=do.call('rgb', as.list(runif(3, .8, 1))), border=NA)
 
  rect(pl, 1.5, 4, 4.5, col=do.call('rgb', as.list(runif(3, .8, 1))), border=NA)
  rect(pl, 5.5, 4, 14.5, col=do.call('rgb', as.list(runif(3, .8, 1))), border=NA)
  rect(pl, 14.5, 4, 20.5, col=do.call('rgb', as.list(runif(3, .8, 1))), border=NA)
 
  text(2, 1:20, advR.chap)
  text(hl/2, 5.5, "Foundations")
  text(hl/2, 11, "Functionalnprogramming")
  text(hl/2, 14, "Computingnon thenlanguage")
  text(hl/2, 18, "Performance")
  text((4+pl)/2, 3, "IntroductorynR")
  text((4+pl)/2, 10, "LanguagenR")
  text((4+pl)/2, 17.5, "Working withnR")
 
  if(length(filename)) {
    dev.off()
  }
}

The part that may be of most interest is that the colors are randomly generated.  Not all colors are allowed — they can only go so dark.

The post Review of ‘Advanced R’ by Hadley Wickham appeared first on Burns Statistics.

To leave a comment for the author, please follow the link and comment on their blog: Burns Statistics » R language.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.