The Basics of R

The R Files Logo

It might be an exaggeration to state that R is taking over the world, but it is certainly making its mark in hydrology. The software is most commonly used for statistics, data analysis and visualisation, and thus is particularly well-suited to many exploratory research tasks. With the additional capacity to link computationally intensive routines to Fortran, C or C++ codes, it is also increasingly being used for nuermically-intensive work such as hydrological modelling and optimisation. Both the R platform and its many packages are completely open source, and available for free via the Comprehensive R Archive Network website. Versions of R exist for the Unix, Windows and MacOS platforms.

If you haven’t used R before, you can download the official introductory guide here. There are plenty of online tutorials and videos that you can discover via Google, as well as a large number of dedicated blogs. For those preferring old-fashioned paper manuals, here are a few we particularly like:

  • The R Book, by Michael J Crawley. Now in its second edition, this would probably be one of the most comprehensive references available for all the R basics.
  • The Art of R Programming – A Tour of Statistical Software Design, by Norman Matloff. This is more focused to those who want to use R for software design, and covers the basic data and programming structures as well as more advanced topics such as object oriented design, improving the coding speed, parallel R, and interfacing to other languages (e.g. C, C++ and Python).
  • Software for Data Analysis – Programming with R, by John M Chambers. This is also a great book focusing on software design, covering a very similar subject material to the book by Norman Matloff.
  • R Graphics, by Paul Murrell. R has so many plotting capabilities that it is hard to keep track of them all. This book provides a good entry point, focusing on the basic syntax of R graphics as well as many of the specialised packages.
  • ggplot2, by Hadley Wickham. This book describes the package bearing the same name, which has some beautiful graphics capabilities. If you’re keen to develop striking figures for your next paper, this might represent a good place to start.

There are also plenty of specialist books describing how to use R for Bayesian computation, Monte Carlo methods, time series analysis, generalised additive modelling, spatial data analysis and many more.

Finally, for advanced users wanting to write your own packages, you can start with resources here and here. Because R is originally written for Unix, building your own package can be a little bit more difficult if you’re using a Windows machine, but I’ve followed the instructions on this page and gotten it to work.

Note: The tools and resources listed on this page are not exhaustive. They are a cross section that reflects those we have used and have found helpful. There may well be other resources we are not aware of, or have not (yet) used, and in this event, please feel free to contact The HydroFiles. If you require assistance with any tools listed on this site please seek support in the relevant dedicated forums.

Leave a Reply

Your email address will not be published. Required fields are marked *