X2RR-compatible output routines for AD Model Builder, C, C++, and Fortran


X2R solves the following problem:  Given a numerical model written in a compiled language, how can its structured output easily be transferred to R for postprocessing (graphing, further analysis)?

Software description

X2R is composed of three similar sets of software: C2R, ADMB2R, and For2R.  Each contains output routines to simplify transfer of complicated data structures from models written in a compiled language to R or S-PLUS.*

When X2R routines are called, the user's data is written as a structured ASCII file.  That file can be read by R or S-PLUS with a single dget() function call to become a data object of type list.  That list may contain components such as data frames, matrices, and other lists.  Thus not only numeric and character data, but also data structure, variable names, and dimension names can be transferred.

These are not R or S-PLUS functions; rather they are subroutine libraries to be used and compiled with programmers' own modeling codes.  Source code, examples, and users' guides are supplied.

• For2R is for use with the Fortran 90 and Fortran 95 languages. It should be compatible with any standard-conforming Fortran 95 compiler. Because Fortran 77 is (very nearly) a subset of Fortran 95, For2R may be called from Fortran 77, as long as a Fortran 95 compiler is used. We expect For2R to be compatible with Fortran 2003 compilers.

• C2R is for use with the C and C++ languages. It should work with any C compiler.

• ADMB2R is for use with AD Model Builder*, a code generator that requires a C++ compiler. Because of idiosyncracies in ADMB, ADMB2R may not work properly with all compilers. We have used it successfully with the gcc and Borland* compilers.

Related software

For those working in fish stock assessment, we offer a related group of R functions, FishGraph. The FishGraph functions create graphs useful in analysis of fish stock assessments whose output has been saved with X2R. They are equally applicable to assessment models programmed in R, and whose results are generated in a suitable format. At present FishGraph functions only on Windows.

Warranty and license

X2R has been tested and used by the authors. However, any software may contain bugs. These works are classified by NOAA as experimental products, and the user is solely responsible for ascertaining suitability and correct operation. The software is offered with no warranty of any kind.

X2R was written while the authors were employed by or associated with the U.S. National Oceanic and Atmospheric Administration (NOAA). It may be freely redistributed as long as credit is given to the original authors.

Reporting bugs & requesting features

Bug reports, suggestions, and extensions are solicited (send to Prager). The authors will attempt to fix all bugs promptly and to add requested features as time and resources allow.


Michael H. Prager1, Jennifer L. Martin2, and Andi Stephens

1National Marine Fisheries Service, NOAA
101 Pivers Island Road
Beaufort, NC  28516  USA

2 U.S. Geological Survey
384 Woods Hole Road
Woods Hole, MA  02543  USA

email Mike Prager
email Jennifer Martin

* Product disclaimers