Skip to content

Add interactive warnings in FIMS on the R side#1663

Description

@e-perl-NOAA

Describe the problem, idea, or request that you have and, if possible, provide a solution.

I think many of us have seen some R packages like {dplyr} provide a cheeky 馃槈 message of "Did you mean to use = instead of == in your filter() command?" And in our minds (well my mind), we think "Why, yes, I did mean == instead of =, SILLY ME! Thanks for the heads-up!" Apparently this is called "empathetic" 鉂わ笍 software design.

Some packages have taken this a step forward with interactive prompts to double-check your intent or try to move you towards best practices like {pak} asking: "These packages have more recent versions available. Which would you like to update? 1: All, 2: CRAN only, 3: None."

In SS3, we struggled with trying to decide on making something an error which stopped the model run, or a warning ... but so many people ignore warnings 馃槱. Interactive suggestions feel like a great way to MAKE users acknowledge what they are doing/assumptions they are making, and provide information on how to help them decide a better a path forward. There can also be an option to turn the interactive part off if a user knows they will be making a choice against convention for some reason (bridging, testing, etc.).

Idk why, but my brain thought of this while going back and forth with Fernando (gemini/copilot) trying to understand the discussion in issue #326 and so that's why the following example is related to that. It most likely doesn't have correct info/implementation of multinomial or other distributions, but the point of it is to demonstrate a way to use interactive messages.

some_function <- function(data, ask = TRUE) {
  # 1. Check if the data contains non-integers
  is_integer <- all(data == floor(data))
  
  if (!is_integer) {
    
    # 2. THE OVERRIDE: Check if the user explicitly disabled the prompt
    if (!ask) {
      # Use a warning so it gets logged, but don't pause the code
      warning("Non-integer data detected. 'ask = FALSE' specified: Proceeding with legacy fractional fit for bridging.")
      
    } else {
      # 3. Standard interactive check if 'ask' is left as TRUE
      if (interactive()) {
        message("\n--- Data Warning ---")
        message("The multinomial distribution expects integer counts, but you provided fractional numbers.")
        message("Using fractions can invalidate certain statistical tests (like OSA residuals).")
        
        ans <- readline("Do you want to proceed anyway? (Y/n): ")
        
        if (tolower(substr(ans, 1, 1)) == "n") {
          stop("Model fit halted by user. \nAlternative: Try using `fit_logistic_normal()`.", call. = FALSE)
        } else {
          message("Proceeding with fractional multinomial fit...")
        }
        
      } else {
        # Fallback if the environment isn't interactive but 'ask' was left TRUE
        warning("Non-integer data detected. Proceeding, but tests may be invalid.")
      }
    }
  }
  
  # ... continue with the actual TMB/C++ model fitting ...
  print("Fitting model...")
}

Would something like this be useful for any current functions in FIMS? If so, please add them here as a sub-issue with what/where it would be useful to have an interactive warning.

Additional context

No response

Which OS are you seeing the problem on?

No response

Which version of this package are you seeing the problem on?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs discussionDialogue is needed before a next step can be takenstatus: triage_neededThis is not approved for this milestone, do not work on it yet

    Fields

    Priority

    Low

    Start date

    None yet

    Target date

    None yet

    Effort

    Low

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions