This is a compilation of various R exercises and examples created over many years. They have been used mostly in undergraduate civil engineering classes including fluid mechanics, hydraulics, and water resources. This is a dynamic work, and will be regularly updated as errors are identified, improved presentation is developed, or new topics or examples are introduced. I welcome any suggestions or comments.

In what follows, text will be intentionally brief. More extensive discussion and description can be found in any fluid mechanics, applied hydraulics, or water resources engineering text. Symbology in this reference generally follows that Finnemore and Franzini (2002). Fundamental equations will be introduced though the emphasis will be on applications to solve common problems. Also, since this is written by a civil engineer, the only fluids included are water and air, since that accounts for nearly all problems encountered in the field.

Solving water problems is rarely done by hand calculations, though the importance of performing order of magnitude ‘back of the envelope’ calculations cannot be overstated. Whether using a hand calculator, spreadsheet, or a programming language to produce a solution, having a sense of when an answer is an outlier will help catch errors.

Scripting languages are powerful tools for performing calculations, providing a fully traceable and reproducible path from your input to a solution. Open source languages have the benefit of being free to use, and invite users to be part of a community helping improve the language and its capabilities. The language of choice for this book is R (R Core Team 2022), chosen for its straightforward syntax, powerful graphical capabilities, wide use in engineering and in many other disciplines, and by using the RStudio interface, it can look and feel a lot like Matlab® with which most engineering students have some experience.

No introduction to R or RStudio is provided here. It is assumed that the reader has installed R (and RStudio), is comfortable installing and updating packages, and understands the basics of R scripting. A brief overview is provided here, aimed at students at Santa Clara University. More comprehensive materials are readily available, including An Introduction to R by the R Core Team. An excellent set of materials for a course Introduction to Programming with R by Stauffer et al. is also freely available and includes interactive exercises.

As I developed these exercises and text, I learned R through the work of many others, and the excellent help offered by skilled people sharing their knowledge on stackoverflow. The methods shown here are not the only ways to solve these problems, and users are invited to share alternative or better solutions.


This work is provided under a Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0). As a summary, this license allows reusers to distribute, remix, adapt, and build upon the material in any medium or format for noncommercial purposes only, and only so long as attribution is given to the creator. This is a summary of (and not a substitute for) the license.