Skip to content

Commit 4f4657e

Browse files
committed
Fix IAS functions
1 parent 8bcdd70 commit 4f4657e

File tree

3 files changed

+9
-29
lines changed

3 files changed

+9
-29
lines changed

R/DWF_IAS_distribution.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#' @order 2
1010

1111
IAS_distribution <- function(
12-
species = NULL, env_file = ".env", verbose = FALSE, overwrite = FALSE) {
12+
species = NULL, env_file = ".env", verbose = FALSE, overwrite = TRUE) {
1313

1414
# # ..................................................................... ###
1515

@@ -48,7 +48,7 @@ IAS_distribution <- function(
4848
Path_Grid <- Path_TaxaInfo <- Path_GBIF <- Path_eLTER <- Path_EASIN <-
4949
Path_BioReg <- Path_Grid_Ref <- Path_PA <- Path_TaxaInfo_RData <- BiogReg <-
5050
Country <- Species_name2 <- Species_name <- n <- GBIF <- EASIN <- eLTER <-
51-
PA <- species <- `status-decision` <- Path_TaxaCNT <- country <-
51+
PA <- `status-decision` <- Path_TaxaCNT <- country <-
5252
gbif_key <- status_decision <- NULL
5353

5454
# # ..................................................................... ###

R/DWF_IAS_plot.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#' @rdname IAS_data
99
#' @order 3
1010

11-
IAS_plot <- function(species = NULL, env_file = ".env", overwrite = FALSE) {
11+
IAS_plot <- function(species = NULL, env_file = ".env", overwrite = TRUE) {
1212

1313
# # ..................................................................... ###
1414

@@ -287,7 +287,7 @@ IAS_plot <- function(species = NULL, env_file = ".env", overwrite = FALSE) {
287287
# Using ggplot2::ggsave directly does not show non-ascii characters correctly
288288

289289
ragg::agg_jpeg(
290-
filename = out_path, width = 25, height = 26.5,
290+
filename = out_path, width = 25, height = 26.5,
291291
res = 600, quality = 100, units = "cm")
292292
print(Plot)
293293
grid::grid.text(

R/DWF_IAS_process.R

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ IAS_process <- function(env_file = ".env", n_cores = 6L, overwrite = TRUE) {
5959

6060
rm(AllArgs, envir = environment())
6161

62-
withr::local_options(
63-
future.globals.maxSize = 8000 * 1024^2, future.gc = TRUE,
64-
future.seed = TRUE)
65-
6662
# # ..................................................................... ###
6763

6864
# Avoid "no visible binding for global variable" message
@@ -167,21 +163,8 @@ IAS_process <- function(env_file = ".env", n_cores = 6L, overwrite = TRUE) {
167163
.StartTimeDist <- lubridate::now(tzone = "CET")
168164

169165
## Prepare working on parallel -----
170-
IASDT.R::cat_time(
171-
paste0("Prepare working on parallel using ", n_cores, " cores"),
172-
level = 1)
173-
174-
if (n_cores == 1) {
175-
future::plan("future::sequential", gc = TRUE)
176-
} else {
177-
withr::local_options(
178-
future.globals.maxSize = 8000 * 1024^2, future.gc = TRUE,
179-
future.seed = TRUE)
180-
c1 <- snow::makeSOCKcluster(n_cores)
181-
on.exit(try(snow::stopCluster(c1), silent = TRUE), add = TRUE)
182-
future::plan("future::cluster", workers = c1, gc = TRUE)
183-
withr::defer(future::plan("future::sequential", gc = TRUE))
184-
}
166+
IASDT.R::set_parallel(n_cores = n_cores, level = 1)
167+
withr::defer(future::plan("future::sequential", gc = TRUE))
185168

186169
# # .................................... ###
187170

@@ -199,18 +182,15 @@ IAS_process <- function(env_file = ".env", n_cores = 6L, overwrite = TRUE) {
199182
future.packages = c(
200183
"dplyr", "lubridate", "IASDT.R", "purrr", "stringr", "readr", "fs",
201184
"sf", "terra", "readxl", "tidyr", "tidyselect", "ggplot2", "ggtext",
202-
"grid", "tidyterra", "cowplot", "scales"),
185+
"grid", "tidyterra", "cowplot", "scales", "tibble", "magrittr", "ragg",
186+
"grDevices"),
203187
future.globals = c("env_file", "overwrite")) %>%
204188
dplyr::bind_rows()
205189

206190
# # .................................... ###
207191

208192
## Stopping cluster ----
209-
IASDT.R::cat_time("Stopping cluster", level = 1)
210-
if (n_cores > 1) {
211-
snow::stopCluster(c1)
212-
future::plan("future::sequential", gc = TRUE)
213-
}
193+
IASDT.R::set_parallel(stop = TRUE, level = 2)
214194

215195
IASDT.R::cat_diff(
216196
init_time = .StartTimeDist,

0 commit comments

Comments
 (0)