Running examples in ‘sdmTMB-Ex.R’ failed
The error most likely occurred in:

> ### Name: add_barrier_mesh
> ### Title: Transform a mesh object into a mesh with correlation barriers
> ### Aliases: add_barrier_mesh
> 
> ### ** Examples
> 
> if (require("sf", quietly = TRUE) &&
+   require("ggplot2", quietly = TRUE) &&
+   require("dplyr", quietly = TRUE) &&
+   require("INLA", quietly = TRUE)) {
+ 
+ # First, download coastline data for our region.
+ # We will use `bc_coast` from the package data,
+ # but you can recreate it with the following.
+ 
+ # For applied situations on finer scales, you may with to use scale = "large".
+ # For that, first: remotes::install_github("ropensci/rnaturalearthhires")
+ # map_data <- rnaturalearth::ne_countries(
+ #   scale = "medium",
+ #   returnclass = "sf", country = "canada")
+ #
+ # # Crop the polygon for plotting and efficiency:
+ # st_bbox(map_data)
+ # bc_coast <- suppressWarnings(suppressMessages(
+ #   st_crop(map_data,
+ #     c(xmin = -134, ymin = 46, xmax = -120, ymax = 57))))
+ 
+ crs_utm9 <- 3156 # Pick a projection, here UTM9
+ 
+ st_crs(bc_coast) <- 4326 # 'WGS84'; necessary on some installs
+ bc_coast <- st_transform(bc_coast, crs_utm9)
+ 
+ # Project our survey data coordinates:
+ survey <- pcod %>% select(lon, lat, density) %>%
+   st_as_sf(crs = 4326, coords = c("lon", "lat")) %>%
+   st_transform(crs_utm9)
+ 
+ # Plot our coast and survey data:
+ ggplot(bc_coast) +
+   geom_sf() +
+   geom_sf(data = survey, size = 0.5)
+ 
+ # Note that a barrier mesh won't do much here for this
+ # example data set, but we nonetheless use it as an example.
+ 
+ # Prepare for making the mesh
+ # First, we will extract the coordinates:
+ surv_utm_coords <- st_coordinates(survey)
+ 
+ # Then we will scale coordinates to km so the range parameter
+ # is on a reasonable scale for estimation:
+ pcod$X1000 <- surv_utm_coords[,1] / 1000
+ pcod$Y1000 <- surv_utm_coords[,2] / 1000
+ 
+ spde <- make_mesh(pcod, xy_cols = c("X1000", "Y1000"),
+   n_knots = 200, type = "kmeans")
+ plot(spde)
+ 
+ # Add on the barrier mesh component:
+ bspde <- add_barrier_mesh(
+   spde, bc_coast, range_fraction = 0.1,
+   proj_scaling = 1000, plot = TRUE
+ )
+ 
+ # In the above, the grey dots are the centre of triangles that are in the
+ # ocean. The red crosses are centres of triangles that are over land. The
+ # spatial range will be assumed to be 0.1 (`range_fraction`) over land compared
+ # to over water.
+ 
+ # We can make a more advanced plot if we want:
+ mesh_df_water <- bspde$mesh_sf[bspde$normal_triangles, ]
+ mesh_df_land <- bspde$mesh_sf[bspde$barrier_triangles, ]
+ ggplot(bc_coast) +
+   geom_sf() +
+   geom_sf(data = mesh_df_water, size = 1, colour = "blue") +
+   geom_sf(data = mesh_df_land, size = 1, colour = "green")
+ 
+ # Now, when we fit our model with the new mesh, it will automatically
+ # include a barrier structure in the spatial correlation:
+ fit <- sdmTMB(density ~ s(depth, k = 3), data = pcod, mesh = bspde,
+   family = tweedie(link = "log"))
+ fit
+ }
Linking to GEOS 3.10.2, GDAL 3.4.3, PROJ 8.2.1; sf_use_s2() is TRUE

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

This is INLA_23.09.09 built 2023-09-09 13:43:09 UTC.
 - See www.r-inla.org/contact-us for how to get help.
Loading required namespace: INLAspacetime
Failed with error:  ‘there is no package called ‘INLAspacetime’’
Warning in INLA::inla.barrier.fem(mesh, barrier.triangles = land.triangles) :
  Please install the `INLAspacetime` package
 which contains an implementation that runs faster!
Error in x[[3]] : object of type 'symbol' is not subsettable
Calls: sdmTMB ... barnames -> vapply -> FUN -> safe_deparse -> paste -> deparse
Execution halted