diff --git a/R/api_plot_raster.R b/R/api_plot_raster.R index 1d2f08c9..36bea5e3 100644 --- a/R/api_plot_raster.R +++ b/R/api_plot_raster.R @@ -42,7 +42,7 @@ .tile_filter_bands(bands = band) |> .tile_filter_dates(dates = date) |> .crop(roi = roi, - output_dir = tempdir(), + output_dir = .rand_sub_tempdir(), progress = FALSE) } @@ -131,7 +131,7 @@ .tile_filter_bands(bands = band) |> .tile_filter_dates(dates = dates) |> .crop(roi = roi, - output_dir = tempdir(), + output_dir = .rand_sub_tempdir(), progress = FALSE) } # select the files to be plotted @@ -200,7 +200,7 @@ .tile_filter_bands(bands = c(red, green, blue)) |> .tile_filter_dates(dates = date) |> .crop(roi = roi, - output_dir = tempdir(), + output_dir = .rand_sub_tempdir(), progress = FALSE) } @@ -330,7 +330,7 @@ if (.has(roi)) { tile <- tile |> .crop(roi = roi, - output_dir = tempdir(), + output_dir = .rand_sub_tempdir(), progress = FALSE) } # size of data to be read @@ -412,7 +412,7 @@ if (.has(roi)) { tile <- tile |> .crop(roi = roi, - output_dir = tempdir(), + output_dir = .rand_sub_tempdir(), progress = FALSE) } # size of data to be read diff --git a/R/api_utils.R b/R/api_utils.R index 52010fcc..f1a0117c 100644 --- a/R/api_utils.R +++ b/R/api_utils.R @@ -349,3 +349,20 @@ NULL .map_dfc <- function(x, fn, ...) { purrr::list_cbind(lapply(x, fn, ...)) } +#' @title Function that returns a random subdirectory of tempdir() +#' @description Generates a random subdir +#' @noRd +#' @keywords internal +#' @returns Name of a valid subdir of tempdir() +#' +.rand_sub_tempdir <- function() { + new_dir <- FALSE + while (!new_dir) { + new_temp_dir <- paste0(tempdir(), "/", sample(1:10000, size = 1)) + if (!dir.exists(new_temp_dir)) { + dir.create(new_temp_dir) + new_dir <- TRUE + } + } + return(new_temp_dir) +} diff --git a/R/sits_plot.R b/R/sits_plot.R index 6b6454e3..cba4034a 100644 --- a/R/sits_plot.R +++ b/R/sits_plot.R @@ -676,7 +676,7 @@ plot.dem_cube <- function(x, ..., tile <- tile |> .tile_filter_bands(bands = band) |> .crop(roi = roi, - output_dir = tempdir(), + output_dir = .rand_sub_tempdir(), progress = FALSE) } # select the file to be plotted