nmfs-fish-tools/SSMSE

Meanbodywt causing error within run_SSMSE_iter

Closed this issue · 9 comments

When I included meanbodywt data, I got the following error within the run_SSMSE_iter function:             

Error in (function (x, x_name, dat)  :
sample_struct could not be automatically expanded due to list elements meanbodywt, meanbodywt; colnames Std_in, Std_in 

Section of code:
if (!is.null(sample_struct)) {
                sample_struct <- SSMSE:::get_full_sample_struct(sample_struct = sample_struct,
                                                        OM_out_dir = OM_out_dir)
                sample_struct <- SSMSE:::convert_to_r4ss_names(sample_struct)
                sample_struct_hist <- SSMSE:::convert_to_r4ss_names(sample_struct_hist)
              }

Here's where this error is in the codebase:

SSMSE/R/sample_struct.R

Lines 558 to 561 in d1e7714

stop(
"sample_struct could not be automatically expanded due to list ",
"elements ", paste0(error1, collapse = ", "), "; colnames ",
paste0(error2, collapse = ", ")

It means this part of the code is throwing an error:

SSMSE/R/sample_struct.R

Lines 511 to 519 in d1e7714

if (!"Std_in" %in% colnames(x)) {
for (i in unique(x[["FltSvy"]])) {
x[["Std_in"]] <- NA
tmp_std_in <- unique(tmp_dat[tmp_dat[[flt_colname]] == i, "Std_in"])
if (length(tmp_std_in) == 1) {
x[x[["FltSvy"]] == i, "Std_in"] <- tmp_std_in
} else {
error1 <- c(error1, x_name)
error2 <- c(error2, "Std_in")

I think what's happening is there is no "Std_in" column, and it needs to be specified. Could that column be created?

These are the column names that should exist for mean size at age data in the sample_struct:

SSMSE/R/sample_struct.R

Lines 20 to 21 in d1e7714

# mean size
"Year", "Seas", "Fleet", "Partition", "Type", "Std_in",

I renamed the meanbodywt data in sample_struct but am now receiving a different error within the run_SSMSE_iter function, specifically within the get_full_sample_struct function:

Section of code:
if (!is.null(sample_struct)) {
sample_struct <- SSMSE:::get_full_sample_struct(sample_struct = sample_struct,
OM_out_dir = OM_out_dir)
sample_struct <- SSMSE:::convert_to_r4ss_names(sample_struct)
sample_struct_hist <- SSMSE:::convert_to_r4ss_names(sample_struct_hist)
}

Error in (function (x, x_name, dat) :
Column Yr missing from 1 or more data frames in sample_struct. Yr must always be specified

@skylersagarese-NOAA , I'm so sorry, I lead you astray with the wrong names! These are actually the correct column names to be using:

SSMSE/R/sample_struct.R

Lines 36 to 37 in d1e7714

# mean weight or length (depends on Type)
"Yr", "Seas", "FltSvy", "Part", "Type", "Std_in",

I was actually using those headers in my sample_struct object (below).

sample_struct$meanbodywt
Yr Seas FltSvy Part Type Std_in
1 2021 7 3 2 2 0.09656815
2 2022 7 3 2 2 0.09656815
...

I am not having any luck trying to identify where this is tripping up in get_full_sample_struct. I assume there is a naming issue somewhere, but am struggling to find it.

Ok, do you think you could email me the code you ran so I can try to replicate it on my end?

Just shared a google drive folder with you (because of confidentiality issues in our data file)...

Got it - I'll try to replicate by tomorrow!

@skylersagarese-NOAA my code was erroring at a different part:

sample_struct <- check_sample_struct(sample_struct)

Ironically, there was a mistake in the error checking function that suggest that the "Std_in" column should be "SE" (it shouldn't). I made a change in commit 14e3f09 (pushed to the fix-sky-isses branch, and then I was able to run run_SSMSE() through an entire iteration with the mean size data (for time's sake, I just did one).

@skylersagarese-NOAA could you test and see if that fix also works for you? If not, I'll have to sort out what I'm doing different from you.

@k-doering-NOAA - that fix worked for me too! Thank you!