R tutorials for the 6th Workshop on Water Resources in Developing Countries at ICTP in Trieste, Italy.
You have three options to complete the tutorials. Regardless of the method you choose, you are expected to achieve the specified goals. Options 2 and 3 offer opportunities to delve deeper into the topics by working with the datasets in your own R scripts.
- First steps in R
- Simple operations
- Functions
- Assignment
- Packages
- A small hydrological sporadic dataset
- Read from XLS
- Exploring it with basic functions
- A larger hydrological sporadic dataset
- Exploring it with package
dplyr
- Exploring it with package
- Plotting with package
ggplot2
- Time series
- Facets
- Box and whiskers plots
- Scatter plots
- Fit a curve
- Reshaping the data with package
tidyr
- Long and wide tables
- Fitting rating curves
- Preliminary analysis
- Package
bdrc
- Compare the rating curves
- Stage hourly time series
- Percentiles
- Annual and daily courses
- Changepoints detection
- Estimating discharge with the rating curves
You can interactively engage with the tutorials directly in your browser without needing to download anything. This option is ideal for beginners.
- Introduction to R and to the hydrological data
- Plot the hydrological data
- Fit the rating curve
- Estimate the discharge using the fitted rating curve
You can install the R package tutorialhydrology
and run the tutorials locally in your RStudio session. This is recommended for those who are familiar with R or are keen to learn it.
- R (≥ 3.5.2)
- RStudio
- R packages:
- Mandatory:
shiny
(≥ 1.6.0),learnr
,readxl
,dplyr
,ggplot2
,tidyr
,lubridate
,bdrc
,changepoint
- Recommended:
readr
,remotes
- Mandatory:
You can install R packages directly from within R/RStudio with install.packages(<package-name>)
. To check if they are already installed and available, use library(<package-name>)
.
Install the R package, load it and launch the tutorials.
library(learnr)
library(remotes)
install_github("jobonaf/tutorialhydrology")
library(tutorialhydrology)
run_tutorial(package = "tutorialhydrology", name = "intro")
run_tutorial(package = "tutorialhydrology", name = "plot")
run_tutorial(package = "tutorialhydrology", name = "fit")
run_tutorial(package = "tutorialhydrology", name = "estimate")
You can also clone the repository tutorialhydrology
from GitHub, build the package and then run the tutorials locally. This option is only possible for advanced R users.
The same as option 2, plus git
.
- Clone from GitHub
- Use the command
git clone https://github.com/jobonaf/tutorialhydrology.git
in your shell, or - In RStudio: File > New Project > Version Control > Git, or
- From GitHub: click Code > Download ZIP, then unzip the folder and create a new RStudio project in it with File > New Project > Existing Directory.
- Use the command
- Open the new RStudio project and use the Build button to build the package.
- Navigate the tutorials in the Tutorial pane and launch the one you are interested in.
- If you want, you can modify them in the folder
inst/tutorials
and rebuild the package.
If you choose options 2 or 3, you can view the dataset descriptions with the command
help(tutorialhydrology)
The package contains three datasets, accessible with the command data(<dataset-name>)
:
-
hourly_n105: Hourly stage data at station N105. A data frame with 176034 rows and 2 columns:
-
datetime
: Time of observation -
H
: Stage level (m)
-
-
obs_discharge: Observed hydrological data. A data frame with 9768 rows and 20 columns:
- Variable, Unit, Value, IdMeasure, Date, TimeStart, TimeEnd, NoBranches (Number of river's branches at the time of the measure), Instrument, Method, NotesMeasure, StationCode, Municipality, Province, Location, River, Basin, SubBasin, Description, NotesStation.
- Includes variables measured in 19 stations:
T_water
,H
,H_bridge
,H_rod
,H_select
,Q
,section_area
,section_width
,depth_ave
,depth_max
,speed_ave
,speed_max
.
-
obs_n105: Observed discharge data at station N105 (Torre river in Tarcento). A data frame with 29 rows and 4 columns:
-
TimeStart
: Begin of sampling time -
StationCode
: ID of the station -
H
: Stage level (cm) -
Q
: River discharge ($m^3/s$ )
-
These datasets allow you to write your own scripts and perform further analyses. Enjoy exploring!
To deploy/publish a tutorial on your shinyapps.io account, use the Publish button provided by the package rsconnect
in RStudio. Alternatively, in an R session, try the following code:
rsconnect::setAccountInfo(
name='<your-username>',
token='<your-token>',
secret='<your-secret>'
)
rsconnect::deployDoc(
doc="<path-to-Rmd-file>",
appName="<short-name>",
appTitle="<webpage-title>"
)