-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow_preview.R
57 lines (47 loc) · 1.69 KB
/
show_preview.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#' Preview data
#'
#' \code{show_preview} opens the dataset on mapping platform of
#' the Swiss Confederation (\url{https://map.geo.admin.ch}).
#'
#' @importFrom utils menu browseURL
#'
#' @param dataset character string containing the name of an available dataset.
#' Use \code{get_available_geodata} to find the corresponding names.
#' @param available_geodata result of a previous call with \code{get_available_geodata}.
#' Optional argument.
#'
#' @details The acquisition and use of data or services is free of charge,
#' subject to the provisions on fair use (see \url{https://www.geo.admin.ch/terms-of-use}).
#'
#' @examples
#' # Shows the preview of the travel time to 6 major centres by public transport
#' show_preview("ch.are.reisezeit-oev")
#'
#' @export
#'
show_preview <- function(dataset, available_geodata) {
# Download available datasets
if (missing(available_geodata)) available_geodata <- get_available_geodata(include_links = T)
# Search, check and clarify
res <- search_geodata(dataset, include_links = T, available_geodata = available_geodata)
if (nrow(res) == 0) {
message("No matching dataset found.\n")
return(invisible())
}
if (nrow(res) > 1) {
choice <- utils::menu(
choices = c(res[["name"]], "No."),
title = "The entered dataset name is ambiguous. Would you like to preview one of the following datasets?"
)
} else {
choice <- 1
}
# End if none is to be displayed
if (choice == nrow(res) + 1) return(invisible(res))
# Visit geocat
if (is.na(res[["preview"]][[choice]])) {
message("No preview is available for the selected dataset.\n")
return(invisible())
}
utils::browseURL(res[["preview"]][[choice]])
}