pbs-assess / sdmTMB

:earth_americas: An R package for spatial and spatiotemporal GLMMs with TMB
https://pbs-assess.github.io/sdmTMB/
183 stars 26 forks source link

`plot_anisotropy()` fails when `sdmTMB(anisotropy = FALSE)` #198

Closed kellijohnson-NOAA closed 1 year ago

kellijohnson-NOAA commented 1 year ago

I know the the results of the title seem logical but when a fit is in a list of many fits I like to iterate over the large list using {purrr} so it would be nice if the function just exited nicely instead of giving

Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x),  : 
  'data' must be of a vector type, was 'NULL'

with no information in traceback() to know where the error came from. I propose adding an if statement before the following line to check and see if the H matrix exists. Then, a warning, message, or stop statement could be given if FALSE. https://github.com/pbs-assess/sdmTMB/blob/3396d445cda0a6454145e986892a228877609edc/R/plot.R#L46 I am happy to submit a pull request if this seems helpful.

seananderson commented 1 year ago

Yes, that would be nice. Sure, a pull request would be welcome. I guess a cli::cli_inform() and returning nothing would be enough. In a perfect world, I guess it could just plot the isotropic covariance, but I don't think it's worth the trouble (and plot_anisotropy() is not coded very elegantly right now).