Call 'EPANET' Functions to Simulate Pipe Networks

Enables simulation of water piping networks using 'EPANET'. The package provides functions from the 'EPANET' programmer's toolkit as R functions so that basic or customized simulations can be carried out from R. The package uses 'EPANET' version 2.2 from Open Water Analytics <>.

CRAN RStudio mirror downloads CRAN version Build Status Coverage Status epanet2toolkit is an R package for simulating water networks using Epanet. The package provides functions from the Epanet programmer's toolkit as R functions so that basic or customized simulations can be carried out from R. The package uses Epanet version 2.1 from Open Water Analytics.

In addition to this readme page and the package manual, the paper An R package for EPANET simulations is published in Environmental Modelling & Software and is also available as a preprint.


Install the latest release from CRAN


Or, install the development version from


Getting Started

After installation, the package needs to be loaded for use.


A brief introduction is available in the package help and each function has its own help page. Functions provided by the package map directly to functions in Epanet's API and integrate with the R system for handling exceptions. Thus the function ENgetnodeindex( nodeID ) provides the index corresponding to a node ID, or raises an error if such a node ID does not exist.


Running a Full Simulation

The function ENepanet() runs a full simulation and writes the results to a file. A file of simulation results can be analyzed using the package epanetReader.

ENepanet("Net1.inp", "Net1.rpt")

Querying Network Properties

Characteristics of a network can be examined using package functions. Note that Epanet needs to be opened for use and should be closed when the analysis finishes.

ENopen("Net1.inp", "Net1.rpt")

Example Programs

The US EPA website for Epanet includes example programs for a hydrant rating curve and chlorine dosage analysis. An implementation of those programs using R and epanet2toolkit are included with the package as tests:

Programming Notes for Package Developers

Epanet provides a collection of functions known as the programmer's toolkit or API for building customized simulations. epanet2toolkit makes these functions callable from R.

Functions in the Epanet API return an integer error code and provide requested values by reference.

int ENgetnodeindex(char *nodeID, int *nodeindex); 

A C toolkit function such as ENgetnodeindex takes two arguments: the node ID, and a pointer to an integer variable where the requested nodeindex is stored. The function returns an integer error code. Using the C function requires allocating an integer for storing the requested node index and passing a pointer to the storage location to the function. Checking the returned error code is optional, but is good practice.

epanet2toolkit integrates Epanet into R by providing two layers of wrapping. First, the existing functions of Epanet's C API are wrapped by new C functions with return type 'void' or 'SEXP' so that they can be called from R. Second, new R functions are provided to call these new C functions. The R functions provide some argument checking and also check the error codes returned by Epanet.


Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.5.1 by Bradley Eck, 8 months ago

Browse source code at

Authors: Ernesto Arandia [aut] , Bradley Eck [aut, cre] , Lew Rossman [aut] , Michael Tryby [ctb] , Sam Hatchett [ctb] , Feng Shang [ctb] , James Uber [ctb] , Tom Taxon [ctb] , Hyoungmin Woo [ctb] , Jinduan Chen [ctb] , Yunier Soad [ctb] , Mike Kane [ctb] , Demetrios Eliades [ctb] , Will Furnass [ctb] , Steffen Macke [ctb] , Marios Kyriakou [ctb] , Elad Salomons [ctb] , Maurizio Cingi [ctb] , Bryant McDonnell [ctb] , Angela Marchi [ctb] , Markus Sunela [ctb] , Milad Ghiami [ctb] , IBM Corp. [cph] , Open Water Analytics [cph]

Documentation:   PDF Manual  

MIT + file LICENSE license

Suggests testthat, epanetReader

Suggested by epanetReader.

See at CRAN