HydroR Plugin

HydroR is a HydroDesktop extension that provides an interface between HydroDesktop and the R statistical computing environment. In a nutshell, R is a language and environment for statistical computing and graphics. R provides a wide variety of statistical and graphical techniques and is highly extensible. R is available as free software, and can be downloaded from http://www.r-project.org/.

HydroR provides a scripting interface within which R commands can be written and then sent to the R Console for execution. HydroR provides functionality for automatically generating the R code needed to retrieve any of the hydrologic time series data that have been downloaded and stored within HydroDesktop’s data repository database into an R List object. The R list object contains all of the metadata for a time series and a Data Frame object that contains the time series data values. Once the data have been transferred from the HydroDesktop database into an R List object, they can be manipulated using any of the graphical or statistical tools that R, or any extended R packages, provide.


On this Page:
Opening HydroR
Loading Data Series
Creating R Commands
Executing R Code
Saving R Scripts
Closing the R Console
Changing the R Version

Opening the HydroR Extension

Follow the steps below to open the HydroR extension within HydroDesktop:

1. If you don’t have HydroDesktop open already, open it by clicking on Start / All Programs / CUAHSI HIS / HydroDesktop / HydroDesktop
2. The HydroR extension is loaded by default, but if you do not see a HydroR tab at the top of your HydroDesktop window, click on the “File” tab at the top of the HydroDesktop window and then click on “Extension Manager” to show the list of available HydroDesktop Extensions.


3. Make sure that the box next to the HydroR extension is checked and then click the “Close” button. You will notice that a new tab called “HydroR” has been added to the HydroDesktop Window.
4. Click on the “HydroR” tab to access its functionality. The following window shows the HydroR tab.


Loading Data Series Into R from HydroDesktop

Once you have discovered and downloaded some time series data into HydroDesktop, you can use the following steps to begin loading any of those time series into R for analysis:

1. Select any of the data series shown in the HydroDesktop Series Selection tool by clicking on the check box to the left of the data series.
2. Click the “Generate R Code” button on the HydroR ribbon. You will notice that new lines of R code have been added to the HydroR script window. These lines of code can be executed by the R console to load the selected data series from the HydroDesktop data repository database into R as an R List object. In the following example, a single data series has been selected and will be loaded into an R List object called “data0.”



Creating R Commands in the HydroR Script Editor

Any command that can be executed within R can be typed into the HydroR script editor. The following figure shows an R script that first loads a data series into an R List object and then determines the number of data values within the data series and some simple descriptive statistics of the data values.


Executing R Code from the HydroR Script Editor

Use the following steps to execute R commands from the HydroR script editor:

1. Open the R Console within HydroR by clicking on the “Start R” button on the HydroR ribbon. You will notice that the R Console opens within the HydroR tab.


NOTE: The first time you start the R console, you may get a pop-up dialog that asks you to navigate to the location of your R installation. Follow the instructions on the form. You may also have to choose a R CRAN Mirror site from which the HydroR extension will download a number of R packages to complete the installation. Choose a CRAN mirror site that is near you and then click “OK.”

2. On the HydroR ribbon, you will notice that there are three buttons for sending code from the HydroR script editor to the R console for execution: 1) Send Line, 2) Send Selection, and 3) Send All. Send Line sends the currently selected line to the R Console, Send Selection sends all of the selected lines to the R Console, and Send All sends everything within the HydroR script editor to the R Console. Select a number of lines by clicking and dragging in the script editor and then click the “Send Selection” button to send them to the R console.



3. You will notice that the lines from the script editor are sent to the R console and executed.

Saving R Scripts and Opening Them Later

Follow the steps below to save a script that you have written in the HydroR script editor to your hard disk for later use:

1. Click on the “Save Script” button on the HydroR ribbon. A file dialog window will open asking you where you want to save your script.


2. Select a location on disk to save your file and then provide a file name. The file will be stored as a text file with a ”.r” extension. Click the “Save” button.
3. To open a script that you have saved to your hard disk, click the “Open Script” button on the HydroR ribbon. The file dialog window will open asking you where your R script is located on your hard disk.



4. Navigate to your R script that you have saved and select it in the file dialog box. Then click the “Open” button. Your saved script will be loaded into the HydroR script editor.

R Commands Included in the HydroR Package for R

The HydroR package for R, which is used by the HydroR extension for HydroDesktop, includes a number of useful functions for interacting with hydrologic time series data stored within the HydroDesktop data repository database. The following table describes the included functions and shows examples of the included commands.


Closing the R Console

When you are done using the R Console, you can close it using the following steps:

1. Click the “Close R” button on the HydroDesktop ribbon. The following window will appear asking if you want to save the R Workspace Image.


2. Choose whether you want to save your R workspace image containing any R objects that you have loaded.

Changing the R Version

When you have multiple versions of R, you can check and change the version of R that is used by HydroR with the following steps:

1. Click the “Path to R” button on the HydroDesktop ribbon. The following window will appear asking if you want to change the path to R.


2. Use the Browse... button to locate a different version of R on your computer.