lkerr / groundfish-MSE

Development of Robust Management Strategies for Northeast Groundfish Fisheries in a Changing Climate
MIT License
4 stars 2 forks source link

get_estF, get_nextF, get_proj errors #286

Open mle2718 opened 1 year ago

mle2718 commented 1 year ago

@jerellejesse --- this is a little strange.

I've been running the code in EconOnly2 (which is quite similar to Dev) for a long time with no problems. I've almost always been running a model with at least 2 rows of mproc.csv. I have to switch over to a new server and I started getting an error here:

if(mproc$rhoadjust==TRUE & y>fmyearIdx & stockEnv$Mohns_Rho_SSB[y]>0.15)

because the length of the statement inside the if statement is longer than 1.

I am almost positive that this is an R version issue. My old server is on R 4.0.5. The new server is on R 4.3.0 This code:

t<-c(FALSE, FALSE, TRUE, FALSE)

if (t=="FALSE"){
  t
}

Produces this:

[1] FALSE FALSE  TRUE FALSE
Warning message:
In if (t == "FALSE") { :
  the condition has length > 1 and only the first element will be used

on R. 4.0.5. It produces this:

Error in if (t == "FALSE") { : the condition has length > 1

In R.4.3.0

mle2718 commented 1 year ago

I have a hacky fix in https://github.com/lkerr/groundfish-MSE/tree/patch_get_proj : e5e39480bf807c5bca155078e833f4e7a013859a and 0847d6563743179512bce23795d57e0b077711a1

I don't know enough R or programming to know whether this is okay, or if we should do something like this:

get_estF<-function(catchproj,parmgtproj,parpopproj,parenv,Rfun,stockEnv, parrhoadjust){
    nage <- length(parpopproj$sel)
    N <- matrix(0, nrow=1, ncol=nage)
    init <- tail(parpopproj$J1N, 1)

    #Rho-adjustments to SSB if this option is turned on 
    if (parrhoadjust==TRUE & y>fmyearIdx & stockEnv$Mohns_Rho_SSB[y]>0.15){

and then:

 Fest<-get_estF(catchproj=catchproj[1],parmgtproj=parmgtproj,parpopproj=parpopproj,parenv=parenv,Rfun=Rfun,stockEnv=stockEnv, parrhoadjust=mproc$rhoadjust[m])