## get all the files, though avoid re-downloading
download_it <- function(x, path = "geotiff") {
file <- file.path(path, basename(x))
if (!file.exists(file)) {
curl::curl_download(x, file)
return(TRUE)
}
FALSE
}
#' Built-in example
#'
#' Download 18 example files in GeoTIFF format (total 12 Mb).
#'
#' @return data frame of file names and their start date
#' @export
#' @importFrom tibble tibble
#' @importFrom utils askYesNo
#' @importFrom purrr map_lgl
#' @examples
#' \dontrun{
#' files <- get_example_data()
#' }
get_example_data <- function() {
appdir <- getOption("xytract.appdir")
cache <- appdir$cache()
ok <- TRUE
# if (interactive()) ok <- utils::askYesNo(sprintf("Download files to %s", cache))
if (!ok) {
stop("no files downloaded")
}
dirtarget <- file.path(cache, "geotiff")
dir.create(dirtarget, showWarnings = FALSE, recursive = TRUE)
## TRUE if we downloaded it, FALSE if it was already there
test <- unlist(lapply(dat$fn, download_it, path = dirtarget))
## now build a file-db
tibble::tibble(fullname = list.files(dirtarget, full.names = TRUE, pattern = "tif$"),
date = as.POSIXct(strptime(basename(fullname), "N_%Y%m%d", tz = "UTC")))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.