Reading report files using R
I have written a useful R function that reads the contents of a report
file (or any output file) and stores the contents in R in the form of a
list object. This function is capable of reading single variables,
vectors, and 2-D arrays (including ragged arrays). The R-code was
inspired by some earlier code developed by George Watters.
The format of *.tpl code requires the object name be printed first then the value(s), e.g.:
Once the above line has been read into R the bt vector will be available as A$Biomass, where A is the list object, and Biomass is the name of the bt vector.
To use this function, copy and past the R-code below and and save this file as "reptoRlist.R". Then source this file in R (or put it at the top of your R-script). The function requires a file name argument (e.g., fn="MyModel.rep"). To read the contents of a report file, simply use:
Then all of the objects in your report file will be stored in the list object A.
reptoRlist = function(fn)
vnam=ifile[idx] #list names
nv=length(vnam) #number of objects
for(i in 1:nv)
if(i!=nv) irr=match(vnam[i+1],ifile) else irr=length(ifile)+1 #next row
if(is.numeric(dum))#Logical test to ensure dealing with numbers
A vnam[i ]=dum