Skip to content

Commit

Permalink
new function for random temporary subdirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbertocamara committed Nov 12, 2024
1 parent 703b1b0 commit abd0ed4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
10 changes: 5 additions & 5 deletions R/api_plot_raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions R/api_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion R/sits_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit abd0ed4

Please sign in to comment.