flr/FLXSA

Error in h(simpleError(msg, call)) : error in evaluating the argument 'X' in selecting a method for function 'lapply': negative length vectors are not allowed

Opened this issue · 31 comments

Tried to run FLXSA function but getting error

FLXSA.control.aa <- FLXSA.control(x=NULL, tol=1e-09, maxit=30, min.nse=0.3, fse=0.5, rage=1, qage=3, shk.n=TRUE, shk.f=TRUE, shk.yrs=2, shk.ages=2,window=100, tsrange=20, tspower=3, vpa=FALSE)

aa.xsa <- FLXSA(aa.stk, aa.idx, FLXSA.control.aa)

Error in h(simpleError(msg, call)) :
error in evaluating the argument 'X' in selecting a method for function 'lapply': negative length vectors are not allowed

Could I get access to the input stock and indices objects?

Could I get access to the input stock and indices objects?

Sorry for the delay replying to you, but I was in a sea trip.

I've attached the data you requested.
DATA_XSA.zip

@iagomosqueira
Sorry for the delay replying to you, but I was in a sea trip.

I've attached the data you requested.
DATA_XSA.zip

There was some information missing for FLXSA to work. discards.n and discards.wt needs to be specified, as 0 if that is the case, and then catch.n and catch.wt updated. Also, the plusgroup needs to be set to match what FLXSA assumes, last age

Please check if 0 and 4 are OK as minimum and maximum ages for fbar(). The ages considered to be fully selected should be used there. The example below sets them to 1 and 3, just as example.

This code runs here, could you please check and let us know?

Obviously the time series is pretty short, so results should be interpreted with caution. You could consider taking a look at FLa4a as a statistical model that can tell you quite a bit more about the quality of the fit and the information the data is really giving.

library(FLXSA)

stk <- readFLStock('DATA_XSA/MUT1214_1.IND')

# SET discards to zero
discards.n(stk) <- 0
discards.wt(stk) <- landings.wt(stk)

# COMPUTE catch
catch(stk) <- computeCatch(stk, "all")

# SET plusgroup
range(stk, 'plusgroup') <- 4

# CHECK minfbar and maxfbar, 0-4 is OK?
range(stk)

# CHANGE if needed, for example
range(stk, c('minfbar', 'maxfbar')) <- c(1, 3)

idx <- readFLIndex('DAT_XSA/MUTTUNEFF1.DAT')

FLXSA.control.aa <- FLXSA.control(x=NULL, tol=1e-09, maxit=30, min.nse=0.3, fse=0.5, rage=1, qage=3, shk.n=TRUE, shk.f=TRUE, shk.yrs=2, shk.ages=2,window=100, tsrange=20, tspower=3, vpa=FALSE)

aa.xsa <- FLXSA(stk, idx, FLXSA.control.aa)

library(ggplotFL)

plot(aa.xsa + stk)

@iagomosqueira
I can't express my gratitude for your help.

I tried considering your advices, however I get this error

aa.xsa <- FLXSA(stk, idx, FLXSA.control.aa)
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'X' in selecting a method for function 'lapply': negative length vectors are not allowed

I do not get that error. Could you please check what version of R, FLCore and FLXSA are you running?

R.version
packageVersion('FLCore')
packageVersion('FLXSA')

Did you install from the FLR repository?

platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 4
minor 0.2
year 2020
month 06
day 22
svn rev 78730
language R
version.string R version 4.0.2 (2020-06-22)
nickname Taking Off Again

packageVersion('FLCore')
[1] ‘2.6.15’
packageVersion('FLXSA')
[1] ‘2.6.4’

And yes, I install it from repository

I am testing it now in R 4.0.3, on Windows 10 64 bit, packages re-installed from the FLR repository, and I do not get that error.

Can you please save the objects created in your session

save(stk, idx, file="aa.RData")

and post it here?

The files are not different. I have also tested it with R 4.0.2 and it works here.

Just to check things, does the FLXSA example run for you?

data(ple4)
data(ple4.indices)
res <- FLXSA(ple4, ple4.indices)

@iagomosqueira

No

data(ple4)
data(ple4.indices)
res <- FLXSA(ple4, ple4.indices)
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'X' in selecting a method for function 'lapply': negative length vectors are not allowed

So nothing to do with your data then. What version of iterators do you have?

packageVersion('iterators')

What do you get if you call

iter

I think the call to iter inside an lapply is not dispatching correctly.

packageVersion('iterators')
[1] ‘1.0.13’

iter
standardGeneric for "iter" defined from package "iterators"

function (obj, ...)
standardGeneric("iter")
<environment: 0x000001dc3501c818>
Methods may be defined for arguments: obj
Use showMethods("iter") for currently available ones.

At this point I can only think of the option of installing R 4.0.3, just to have a clean R installation, and then install only iterators from CRAN and FLXSA from FLR. Is that possible for you? Your 4.0.2 installation will remain untouched.

I am afraid it is very difficult for me to fix the problem when I cannot replicate it.

@iagomosqueira

R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Workspace loaded from C:/Users/olfab/OneDrive/Desktop/MUT_STOCK ASSESSMENT_2020/MUT_ASSESSMENT_2020/MUT_TUN_2020/.RData]

Loading required package: FLXSA
Loading required package: FLCore
Loading required package: lattice
Loading required package: iterators
FLCore (Version 2.6.15, packaged: 2020-05-26 19:36:47 UTC)
Loading required package: FLAssess

Restarting R session...

install.packages("iterators")
Installing package into ‘C:/Users/olfab/OneDrive/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.0/iterators_1.0.13.zip'
Content type 'application/zip' length 343160 bytes (335 KB)
downloaded 335 KB

package ‘iterators’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\olfab\AppData\Local\Temp\Rtmpe2eGKX\downloaded_packages

install.packages("FLXSA", repos="http://flr-project.org/R")
Installing package into ‘C:/Users/olfab/OneDrive/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
trying URL 'http://flr-project.org/R/bin/windows/contrib/4.0/FLXSA_2.6.4.zip'
Content type 'application/zip' length 440017 bytes (429 KB)
downloaded 429 KB

package ‘FLXSA’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\olfab\AppData\Local\Temp\Rtmpe2eGKX\downloaded_packages

setwd("C:/Users/olfab/OneDrive/Desktop/MUT_STOCK ASSESSMENT_2020/MUT_ASSESSMENT_2020/MUT_TUN_2020/RUN_BENCHMARK/DATA_XSA")
library(FLXSA)
Loading required package: FLCore
Loading required package: lattice
Loading required package: iterators
FLCore (Version 2.6.15, packaged: 2020-05-26 19:36:47 UTC)
Loading required package: FLAssess
stk <- readFLStock('MUT1214_1.IND')
discards.n(stk) <- 0
discards.wt(stk) <- landings.wt(stk)
catch(stk) <- computeCatch(stk, "all")
range(stk, 'plusgroup') <- 4
range(stk)
min max plusgroup minyear maxyear minfbar maxfbar
0 4 4 2010 2019 0 4
range(stk, c('minfbar', 'maxfbar')) <- c(1, 4)
idx <- readFLIndex('MUTTUNEFF1.DAT')
FLXSA.control.aa <- FLXSA.control(x=NULL, tol=1e-09, maxit=30, min.nse=0.3, fse=0.5, rage=1, qage=3, shk.n=TRUE, shk.f=TRUE, shk.yrs=2, shk.ages=2,window=100, tsrange=20, tspower=3, vpa=FALSE)
aa.xsa <- FLXSA(stk, idx, FLXSA.control.aa)
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'X' in selecting a method for function 'lapply': negative length vectors are not allowed

We will need to debug it in your machine, and see where the errror is coming from. If you call

 trace("FLXSA", browser, exit=browser, signature = c("FLStock", "FLIndices"))

and then

 aa.xsa <- FLXSA(stk, idx, FLXSA.control.aa)

you will be going line by line inside the FLXSA method. Can you keep pressing enter until you get an error message and let me know in what line it stops?

This bug is due to the negative interaction between FLXSA's C++ code and RStudio and only in Windows we saw in #6. Quick solution is to run the code in plain R. Not sure there will be resources available to fix this, given than XSA has very limited use and it affects a single use case.

Dear IagoI am returning to you because I had a problem when runing XSA on MUT I get an error after runing this command: aa.stk <- readFLStock("MUT1214_1.ind", no.discards=TRUE)
Error in readVPA(file, quiet = quiet, sep = sep, na.strings = na.strings) :

This bug is due to the negative interaction between FLXSA's C++ code and RStudio and only in Windows we saw in #6. Quick solution is to run the code in plain R. Not sure there will be resources available to fix this, given than XSA has very limited use and it affects a single use case.

Could you please show what is the error message that readVPA returns?

Could you please show what is the error message that readVPA returns?

Error in readVPA(file, quiet = quiet, sep = sep, na.strings = na.strings) :

Could you please share the VPA files? Either here or by email

Could you please share the VPA files? Either here or by email
@iagomosqueira
DATA_XSA.zip

What version of R and FLCore do you have? This works for me here, R 4.12 and FLCore 2.6.18

library(FLCore)

stk <- readFLStock("DATA_XSA/MUT1214_1.IND")

discards.n(stk) <- 0
discards.wt(stk) <- landings.wt(stk)

catch(stk) <- computeCatch(stk, "all")

ind <- readFLIndex("DATA_XSA/MUTTUNEFF1.dat")

What version of R and FLCore do you have? This works for me here, R 4.12 and FLCore 2.6.18

library(FLCore)

stk <- readFLStock("DATA_XSA/MUT1214_1.IND")

discards.n(stk) <- 0
discards.wt(stk) <- landings.wt(stk)

catch(stk) <- computeCatch(stk, "all")

ind <- readFLIndex("DATA_XSA/MUTTUNEFF1.dat")

@iagomosqueira
R version: 4.0.3
FLCore version: 2.6.15

I have test it with R 4.0.5 and FLCore 2.6.16, the closest I have to your setup, and it works fine. readFLStock has not changed for a long time. Can you call

traceback()

after the error and post the output?

@iagomosqueira

aa.stk <- readFLStock("MUT1214_1.ind", no.discards=TRUE)
Error in readVPA(file, quiet = quiet, sep = sep, na.strings = na.strings) :

traceback()
3: stop()
2: readVPA(file, quiet = quiet, sep = sep, na.strings = na.strings)
1: readFLStock("MUT1214_1.ind", no.discards = TRUE)

Are you running this in Windows? And from RStudio?

Are you running this in Windows? And from RStudio?

@iagomosqueira
in windows but from R and not from RStudio

Are you running this in Windows? And from RStudio?

@iagomosqueira in windows but from R and not from RStudio

@iagomosqueira
Tried after installing the packages and got the same error
tk <- readFLStock("DATA_XSA/MUT1214_1.IND")
Error in readVPA(file, quiet = quiet, sep = sep, na.strings = na.strings) :

@iagomosqueira

No

data(ple4)
data(ple4.indices)
res <- FLXSA(ple4, ple4.indices)
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'X' in selecting a method for function 'lapply': negative length vectors are not allowed

Hi Olfa and Iago, I have done some checking with browser(), because I am having the same issue on my windows machine. So far, I am getting FLXSA to run when I set diag.flag=FALSE

test <- FLXSA(ple4, ple4.indices,diag.flag=FALSE)

So getting closer where to look.

The test above runs on windows with either diag.flag=TRUE or FALSE with the latest version of FLCore from R-Universe, 2.6.20.9100. Could you confirm @Henning-Winker what version do you have?