# Hydraulics and Water Resources: Examples Using R

Professor, Civil, Environmental, and Sustainable Engineering Department, Santa Clara University*2024-05-21*

# Preface

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 for hydraulics in this reference generally follows that of Finnemore and Maurer (2024). 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.

## Introduction to R and RStudio

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. Some resources that can provide an introduction to R include:

- A brief overview, aimed at students at Santa Clara University.
- An Introduction to R, a comprehensive reference by the R Core Team.
- Introduction to Programming with R by Stauffer et al., materials for a university course, including interactive exercises.
- R for Water Resources Data Science, with both introductory and intermediate level courses online.

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.

## Citing this reference

Maurer, Ed, 2023. Hydraulics and Water Resources: Examples Using R, doi:10.5281/zenodo.7576843 https://edm44.github.io/hydr-watres-book/.

## Copyright

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.