`dims` function not recognizing @range "min" and "max" variables in some FLStock objects
marchtaylor opened this issue · 3 comments
I am trying to create an FLStocks object from various individual FLStock objects, and get the following message:
> stocks <- FLStocks(sapply(paste0(stk_names, "_stock"), FUN = get))
Error in if (!is.na(ran["plusgroup"]) & ran["plusgroup"] > dms$max) return("plusgroup is higher than last age") :
missing value where TRUE/FALSE needed
I have tracked this error to the following code, and the error is caused by several stock objects that contain a single age group:
> range(NEP9_stock)
min max plusgroup minyear maxyear minfbar maxfbar
1 1 1 2003 2015 1 1
> unlist(dims(NEP9_stock))
quant age min max year minyear maxyear plusgroup unit
"age" "1" NA NA "13" "2003" "2015" "1" "1"
season area iter
"1" "1" "1"
Somehow, the dims
function is returning NAs even though values are correctly contained in @range. This code worked before my latest FLCore update.
Here in one other example illustrating the issue with a reproducible example:
# make FLStock
flq <- FLStock(FLQuant(rnorm(90), dimnames=list(age=1:10, year=2000:2016)))
range(flq)
unlist(dims(flq))
# trim to one age
flq2 <- trim(flq, year=2000:2005, age=1)
flq2@range["plusgroup"] <- 1
range(flq2)
unlist(dims(flq2))
Thanks in advance for any advice on how I might proceed with creating my FLStocks object.
dims()
returns NA because it is incorrectly inferring that an object with age of length one is a biomass-based one, thus age='all', and max and min then make no sense.
I have now pushed to github a change on dims() that will avoid this and gives the right answer in your example stocks, b429e87
You will need to install the package from github, maybe using
devtools::install_github('flr/FLCore')
Another issue here is what range does. min/max and minyear/maxyear in range are not used by almost any method, and changing them makes no difference. Use dims()
as you do to get the actual dimensions of the object. dims()
does not read the range but extracts the dimensions from the actrual slots.
You can also get a Windows compiled package from Appveyor
https://ci.appveyor.com/api/buildjobs/3b5dmhsv3ovgildq/artifacts/FLCore_2.6.3.9007.zip
Excellent - thanks for the quick fix Iago. This solved my issue.