EcologyR / mappestRisk

Other
1 stars 0 forks source link

Error at map_risk.R#184: [`[[`] indices must be between 1 and the number of layers #64

Closed dario-ssm closed 1 month ago

dario-ssm commented 1 month ago

Hi! I am trying some examples for map_risk() function. I have changed some things regarding visualization with terra::plot() and terra::plet() but I haven't changed anything besides the plotting pieces of code. When I run:

#' risk_rast <- map_risk(t_vals = therm_bounds, path = "downloaded_maps",
#' region = c("Portugal", "Spain"), verbose = TRUE)

The error of the title appears. I have tried running manually the code but I don't get why the last layer disappears after running the terra::app(). Could you give it a glance, @AMBarbosa ? (please pull before changing anything, I have worked on the main branch).

In contrary, if I start a new session and run the complete example, and then:

 risk_rast <- map_risk(t_vals = boundaries_aphid[ , c("tval_left", "tval_right")],
                       path = "~/downloaded_maps", # directory to download data
                       region = "Spain",
                       mask = TRUE,
                       plot = TRUE,
                       interactive = FALSE,
                       verbose = TRUE)

It works (see the image below). image

If I change the region it also works (for example for Morocco):

image

This does not happen when running the same code within the README chunks. I think I am missing some litlle things... thanks in advance!

dario-ssm commented 1 month ago

I have found that this happens when the tvals have NA in any row. Since these are just models that did not adequately converged, I suggest dropping them. If we filter the tvals with tidyr::drop_na() this works perfectly

I'll add this row to the map_risk function.