The Fisheries Library in R (FLR) is a collection of tools for quantitative fisheries science, developed in the R language, that facilitates the construction of bio-economic simulation models of fisheries systems.

FLR builds on the powerful R environment and syntax to create a domain-specific language for the quantitative analysis of the expected risks and effects of fisheries management decision. The classes and methods in FLR consider uncertainty an integral part of our knowledge of fisheries system. […]

## Required packages

To follow this tutorial you should have installed the following packages:

You can do so as follows,

install.packages(c("FLCore"), repos="http://flr-project.org/R")

# Starting with FLR

The main classes (i.e. data structures) and methods (i.e. procedures) in the FLR system are found in the FLCore package. Let’s load it first

library(FLCore)

## The FLQuant class

The basic element on which the FLR classes are based is the FLQuant class. We can look at the structure of the class in its help page

help(FLQuant)

It is a six-dimensional array, in which the first dimension is free to have any name, quant by default, commonly age, while the other five have set names:

• year: year of the data point.
• unit: any subdivision of the data not based on space or time, for example gender (male and female).
• season: any time step shorter than year (e.g. month, quarter, week).
• area: spatial subdivision of data
• iter: multiple iterations of the same process (e.g. bootstrap, Bayesian, Monte Carlo, …)

We can now call the FLQuant() constructor method to see an example with some random numbers

FLQuant(rlnorm(20), dim=c(4,5), quant="age", units="kg")
An object of class "FLQuant"
An object of class "FLQuant"
, , unit = unique, season = all, area = unique

year
age 1       2       3       4       5
1 0.60352 0.97440 0.99065 1.68515 1.36443
2 1.93833 2.09946 3.13919 0.84972 0.53418
3 0.24826 1.51710 5.28007 0.61229 0.59522
4 3.14748 6.16351 1.06234 0.93561 1.43151

units:  kg 

and this produces an FLQuant object with some numbers for ages 1 to 4, and years 1 to 5. The name of the first dimension has been specified to be “age”, while the units of measurement, “kg”, have been stored as an attribute to the array.

An important part of the information associated with any dataset is kept in an FLQuant as the dimnames of the array. For example, we can specify in the constructor call the names of any of the dimensions, by using the dimnames argument

FLQuant(rlnorm(20), units="kg",
dimnames=list(age=0:3, year=2010:2014))
An object of class "FLQuant"
An object of class "FLQuant"
, , unit = unique, season = all, area = unique

year
age 2010     2011     2012     2013     2014
0  5.05653  0.15654  0.69089  1.00484  0.59178
1  0.69980  4.84358  2.49983  2.98628 18.75915
2  1.19544  3.67105  0.28047  3.45236  0.35310
3  0.81529  0.88436  0.41125  2.65102  0.43105

units:  kg 

There are a number of methods and ways to create FLQuant objects from different R objects (vector, matrix, array or data.frame) once loaded into R, please see ?FLQuant and ?as.FLQuant for a complete list of available methods.

Objects of this class have the same properties as any array in R, with some important differences. For example, subsetting on an FLQuant does not drop by default unused dimensions

flq <- FLQuant(rlnorm(20), units="kg",
dimnames=list(age=0:3, year=2010:2014))

flq[1,]
An object of class "FLQuant"
An object of class "FLQuant"
, , unit = unique, season = all, area = unique

year
age 2010    2011    2012    2013    2014
0 0.83273 0.93033 0.57937 0.53811 0.66576

units:  kg 
dim(flq[1,])
[1] 1 5 1 1 1 1

so they remain valid FLQuant objects. Similarly, arithmetic operations on objects of the class, against each other or against numeric vectors, always return an FLQuant object.

flq * 2
An object of class "FLQuant"
An object of class "FLQuant"
, , unit = unique, season = all, area = unique

year
age 2010    2011    2012    2013    2014
0 1.66546 1.86067 1.15873 1.07622 1.33152
1 1.74553 1.58617 1.13461 2.58775 2.61444
2 0.95651 1.61724 0.91591 1.52422 0.46513
3 4.02794 4.84576 1.19348 0.76540 1.54251

units:  kg 
flq + (flq * 2)
An object of class "FLQuant"
An object of class "FLQuant"
, , unit = unique, season = all, area = unique

year
age 2010   2011   2012   2013   2014
0 2.4982 2.7910 1.7381 1.6143 1.9973
1 2.6183 2.3793 1.7019 3.8816 3.9217
2 1.4348 2.4259 1.3739 2.2863 0.6977
3 6.0419 7.2686 1.7902 1.1481 2.3138

units:  kg 
• summary, plot
plot(FLQuant(rnorm(200), dim=c(2,20)))

• FLStock

# References

L. T. Kell, I. Mosqueira, P. Grosjean, J-M. Fromentin, D. Garcia, R. Hillary, E. Jardim, S. Mardle, M. A. Pastoors, J. J. Poos, F. Scott, R. D. Scott; FLR: an open-source framework for the evaluation and development of management strategies. ICES J Mar Sci 2007; 64 (4): 640-646. doi: 10.1093/icesjms/fsm012

## Software Versions

• R version 3.4.1 (2017-06-30)
• FLCore: 2.6.5
• Compiled: Fri Sep 15 15:43:59 2017