From 28daf1f7c21db3a333d9752661e1771ca4d259bb Mon Sep 17 00:00:00 2001 From: Paul Regular Date: Mon, 18 Sep 2023 11:00:38 -0230 Subject: [PATCH] Add conditional use of INLA to examples --- CRAN-SUBMISSION | 4 ++-- R/sim_dist_spde.R | 41 +++++++++++++++++++++++++-------------- man/make_mesh.Rd | 6 ++++-- man/sim_ays_covar_spde.Rd | 33 +++++++++++++++++-------------- 4 files changed, 50 insertions(+), 34 deletions(-) diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION index 1ca92b5..1aa32a0 100644 --- a/CRAN-SUBMISSION +++ b/CRAN-SUBMISSION @@ -1,3 +1,3 @@ Version: 0.1.6 -Date: 2023-09-15 16:02:07 UTC -SHA: 8a489a48ddcde0fd7b4554e983c3c3b9ffd77acf +Date: 2023-09-15 18:15:02 UTC +SHA: 03782485a4ec155145da49da0476c498a1b019e2 diff --git a/R/sim_dist_spde.R b/R/sim_dist_spde.R index e561534..5efdae8 100644 --- a/R/sim_dist_spde.R +++ b/R/sim_dist_spde.R @@ -73,22 +73,25 @@ #' #' \donttest{ #' -#' ## Make a grid -#' my_grid <- make_grid(res = c(10,10)) +#' if (requireNamespace("INLA")) { #' -#' ## Make a mesh based off it +#' ## Make a grid +#' my_grid <- make_grid(res = c(10,10)) #' -#' my_mesh <- make_mesh(my_grid) -#' sim <- sim_abundance(ages = 1:10, years = 1:10) %>% -#' sim_distribution(grid = my_grid, -#' ays_covar = sim_ays_covar_spde(phi_age = 0.8, -#' phi_year = 0.1, -#' model = "spde", -#' mesh = my_mesh), -#' depth_par = sim_parabola(mu = 200, -#' sigma = 50)) -#' plot_distribution(sim, ages = 1:5, years = 1:5, type = "heatmap") +#' ## Make a mesh based off it #' +#' my_mesh <- make_mesh(my_grid) +#' sim <- sim_abundance(ages = 1:10, years = 1:10) %>% +#' sim_distribution(grid = my_grid, +#' ays_covar = sim_ays_covar_spde(phi_age = 0.8, +#' phi_year = 0.1, +#' model = "spde", +#' mesh = my_mesh), +#' depth_par = sim_parabola(mu = 200, +#' sigma = 50)) +#' plot_distribution(sim, ages = 1:5, years = 1:5, type = "heatmap") +#' +#' } #' #' } #' @@ -107,6 +110,12 @@ sim_ays_covar_spde <- function(sd = 2.8, function(x = NULL, ages = NULL, years = NULL, cells = NULL){ + for (pkg in c("INLA")) { + if (!requireNamespace(pkg, quietly = TRUE)) { + stop(paste(pkg, "is needed for make_mesh to work. Please install it."), call. = FALSE) + } + } + na <- length(ages) ny <- length(years) nc <- length(cells) @@ -222,8 +231,10 @@ sim_ays_covar_spde <- function(sd = 2.8, #' #' \donttest{ #' -#' basic_mesh <- make_mesh() -#' plot(basic_mesh) +#' if (requireNamespace("INLA")) { +#' basic_mesh <- make_mesh() +#' plot(basic_mesh) +#' } #' #' } #' diff --git a/man/make_mesh.Rd b/man/make_mesh.Rd index 6787c3f..2c3bc6a 100644 --- a/man/make_mesh.Rd +++ b/man/make_mesh.Rd @@ -36,8 +36,10 @@ are designed for the default grid. Just a basic interface between the grid and i \donttest{ -basic_mesh <- make_mesh() -plot(basic_mesh) +if (requireNamespace("INLA")) { + basic_mesh <- make_mesh() + plot(basic_mesh) +} } diff --git a/man/sim_ays_covar_spde.Rd b/man/sim_ays_covar_spde.Rd index 8010804..b27f47c 100644 --- a/man/sim_ays_covar_spde.Rd +++ b/man/sim_ays_covar_spde.Rd @@ -51,22 +51,25 @@ generate the error term. \donttest{ -## Make a grid -my_grid <- make_grid(res = c(10,10)) - -## Make a mesh based off it - -my_mesh <- make_mesh(my_grid) -sim <- sim_abundance(ages = 1:10, years = 1:10) \%>\% - sim_distribution(grid = my_grid, - ays_covar = sim_ays_covar_spde(phi_age = 0.8, - phi_year = 0.1, - model = "spde", - mesh = my_mesh), - depth_par = sim_parabola(mu = 200, - sigma = 50)) -plot_distribution(sim, ages = 1:5, years = 1:5, type = "heatmap") +if (requireNamespace("INLA")) { + ## Make a grid + my_grid <- make_grid(res = c(10,10)) + + ## Make a mesh based off it + + my_mesh <- make_mesh(my_grid) + sim <- sim_abundance(ages = 1:10, years = 1:10) \%>\% + sim_distribution(grid = my_grid, + ays_covar = sim_ays_covar_spde(phi_age = 0.8, + phi_year = 0.1, + model = "spde", + mesh = my_mesh), + depth_par = sim_parabola(mu = 200, + sigma = 50)) + plot_distribution(sim, ages = 1:5, years = 1:5, type = "heatmap") + +} }