Skip to content

Commit 3ee3b0e

Browse files
committed
check_algorithm_deprecation(): implement toggle to bypass warning *
This is used internally to avoid producing the same warning multiple times in one user call. Following code was used in testing interactively (from #193 (comment)): library(qgisprocess) download.file("https://github.com/inbo/coding-club/raw/main/data/20231214/20231214_land_use_nara_2016_100m.tif", "20231214_land_use_nara_2016_100m.tif") download.file("https://github.com/inbo/coding-club/raw/main/data/20231214/20231214_natura2000_protected_areas.gpkg", "20231214_natura2000_protected_areas.gpkg") zonal_st <- qgis_run_algorithm("native:zonalstatistics", INPUT_RASTER = "20231214_land_use_nara_2016_100m.tif", COLUMN_PREFIX = "landuse_", INPUT_VECTOR = "20231214_natura2000_protected_areas.gpkg", STATISTICS = c("Majority", "Minority")) qgis_show_help("native:zonalstatistics") qgis_get_description("native:zonalstatistics") qgis_get_argument_specs("native:zonalstatistics") qgis_get_output_specs("native:zonalstatistics") qgis_function("native:zonalstatistics")
1 parent d2b7eee commit 3ee3b0e

File tree

6 files changed

+34
-26
lines changed

6 files changed

+34
-26
lines changed

R/qgis-algorithms.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ qgis_providers <- function(
8383
}
8484

8585
#' @keywords internal
86-
assert_qgis_algorithm <- function(algorithm) {
86+
assert_qgis_algorithm <- function(algorithm, check_deprecation = TRUE) {
8787
if (!is.character(algorithm) || length(algorithm) != 1) {
8888
abort("`algorithm` must be a character vector of length 1")
8989
} else if (!qgis_has_algorithm(algorithm)) {
@@ -94,14 +94,15 @@ assert_qgis_algorithm <- function(algorithm) {
9494
)
9595
}
9696

97-
check_algorithm_deprecation(algorithm)
97+
check_algorithm_deprecation(algorithm, skip = !check_deprecation)
9898

9999
invisible(algorithm)
100100
}
101101

102102

103103
#' @keywords internal
104-
check_algorithm_deprecation <- function(algorithm) {
104+
check_algorithm_deprecation <- function(algorithm, skip = FALSE) {
105+
if (skip) return(invisible(NULL))
105106
algs <- qgis_algorithms()
106107
if ("deprecated" %in% colnames(algs)) {
107108
deprecated_algs <- algs$algorithm[algs$deprecated]

R/qgis-arguments.R

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,11 @@ as_qgis_argument <- function(x, spec = qgis_argument_spec(), use_json_input = FA
7979
# serialized as JSON instead of serialized as a command-line argument.
8080
# @param .algorithm_arguments The result of [qgis_get_argument_specs()]
8181
#' @keywords internal
82-
qgis_sanitize_arguments <- function(algorithm, ..., .algorithm_arguments = qgis_get_argument_specs(algorithm),
83-
.use_json_input = FALSE) {
82+
qgis_sanitize_arguments <- function(
83+
algorithm,
84+
...,
85+
.algorithm_arguments = qgis_get_argument_specs(algorithm, check_deprecation = FALSE),
86+
.use_json_input = FALSE) {
8487
dots <- rlang::list2(...)
8588
if (length(dots) > 0 && !rlang::is_named(dots)) {
8689
abort("All ... arguments to `qgis_sanitize_arguments()` must be named.")
@@ -501,7 +504,7 @@ qgis_argument_spec <- function(algorithm = NA_character_, name = NA_character_,
501504

502505
#' @keywords internal
503506
qgis_argument_spec_by_name <- function(algorithm, name,
504-
.algorithm_arguments = qgis_get_argument_specs(algorithm)) {
507+
.algorithm_arguments = qgis_get_argument_specs(algorithm, check_deprecation = FALSE)) {
505508
# These are special-cased at the command-line level, so they don't have
506509
# types defined in the help file. Here, we create two special types
507510
# ELLIPSOID and PROJECT_PATH.

R/qgis-function.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ qgis_function <- function(algorithm, ...) {
3030
assert_qgis()
3131
assert_qgis_algorithm(algorithm)
3232

33-
args <- qgis_get_argument_specs(algorithm)
33+
args <- qgis_get_argument_specs(algorithm, check_deprecation = FALSE)
3434
arg_names <- c(args$name, "PROJECT_PATH", "ELLIPSOID", ".quiet")
3535

3636
# The dots are the default values and are not exposed as

R/qgis-help.R

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#'
55
#' @param algorithm A qualified algorithm name
66
#' (e.g., `"native:buffer"`).
7+
#' @param ... For internal use only.
78
#'
89
#' @returns
910
#' - `qgis_get_description()`: a string.
@@ -47,9 +48,9 @@ extract_type_component <- function(param_element, component) {
4748

4849
#' @rdname qgis_show_help
4950
#' @export
50-
qgis_get_argument_specs <- function(algorithm) {
51+
qgis_get_argument_specs <- function(algorithm, ...) {
5152
if (qgis_using_json_output()) {
52-
help <- qgis_help_json(algorithm)
53+
help <- qgis_help_json(algorithm, ...)
5354
out <- tibble::tibble(
5455
name = names(help$parameters),
5556
description = vapply(help$parameters, "[[", character(1), "description"),
@@ -64,19 +65,20 @@ qgis_get_argument_specs <- function(algorithm) {
6465
# The order of the parameters is alphabetized in JSON but has a
6566
# natural ordering in the parsed help text (which we need for backward
6667
# compatibility)
67-
out_legacy <- qgis_parse_help(algorithm)$arguments
68+
# Setting 'check_deprecation = FALSE' to avoid repetition of same warning
69+
out_legacy <- qgis_parse_help(algorithm, check_deprecation = FALSE)$arguments
6870

6971
out[match(out_legacy$name, out$name), ]
7072
} else {
71-
qgis_parse_help(algorithm)$arguments
73+
qgis_parse_help(algorithm, ...)$arguments
7274
}
7375
}
7476

7577
#' @rdname qgis_show_help
7678
#' @export
77-
qgis_get_output_specs <- function(algorithm) {
79+
qgis_get_output_specs <- function(algorithm, ...) {
7880
if (qgis_using_json_output()) {
79-
help <- qgis_help_json(algorithm)
81+
help <- qgis_help_json(algorithm, ...)
8082
out <- tibble::tibble(
8183
name = names(help$outputs),
8284
description = vapply(help$outputs, "[[", character(1), "description"),
@@ -86,20 +88,20 @@ qgis_get_output_specs <- function(algorithm) {
8688
out[] <- lapply(out, unname)
8789
out
8890
} else {
89-
qgis_parse_help(algorithm)$outputs
91+
qgis_parse_help(algorithm, ...)$outputs
9092
}
9193
}
9294

9395
#' @keywords internal
94-
qgis_help_json <- function(algorithm) {
96+
qgis_help_json <- function(algorithm, check_deprecation = TRUE) {
9597
cached <- help_cache_file(algorithm, json = TRUE)
9698
if (qgis_using_cached_help() && file.exists(cached)) {
97-
check_algorithm_deprecation(algorithm)
99+
check_algorithm_deprecation(algorithm, skip = !check_deprecation)
98100
try(return(jsonlite::fromJSON(readRDS(cached))))
99101
}
100102

101103
assert_qgis()
102-
assert_qgis_algorithm(algorithm)
104+
assert_qgis_algorithm(algorithm, check_deprecation = check_deprecation)
103105

104106
result <- qgis_run(
105107
args = c("--json", "help", algorithm),
@@ -114,15 +116,15 @@ qgis_help_json <- function(algorithm) {
114116
jsonlite::fromJSON(result$stdout)
115117
}
116118

117-
qgis_help_text <- function(algorithm) {
119+
qgis_help_text <- function(algorithm, check_deprecation = TRUE) {
118120
cached <- help_cache_file(algorithm, json = FALSE)
119121
if (qgis_using_cached_help() && file.exists(cached)) {
120-
check_algorithm_deprecation(algorithm)
122+
check_algorithm_deprecation(algorithm, skip = !check_deprecation)
121123
try(return(readRDS(cached)))
122124
}
123125

124126
assert_qgis()
125-
assert_qgis_algorithm(algorithm)
127+
assert_qgis_algorithm(algorithm, check_deprecation = check_deprecation)
126128

127129
result <- qgis_run(
128130
args = c("help", algorithm)
@@ -136,8 +138,8 @@ qgis_help_text <- function(algorithm) {
136138
result$stdout
137139
}
138140

139-
qgis_parse_help <- function(algorithm) {
140-
help_text <- trimws(qgis_help_text(algorithm))
141+
qgis_parse_help <- function(algorithm, check_deprecation = TRUE) {
142+
help_text <- trimws(qgis_help_text(algorithm, check_deprecation = check_deprecation))
141143

142144
sec_description <- stringr::str_match(
143145
help_text,

R/qgis-output.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ qgis_parse_results <- function(algorithm, output) {
44
outputs_list <- output_parsed$results
55
output_names <- names(outputs_list)
66

7-
algorithm_outputs <- qgis_get_output_specs(algorithm)
7+
algorithm_outputs <- qgis_get_output_specs(algorithm, check_deprecation = FALSE)
88

99
Map(
1010
qgis_result_output,
@@ -25,7 +25,7 @@ qgis_parse_results <- function(algorithm, output) {
2525
outputs_list <- lapply(outputs, "[", 2)
2626
output_names <- vapply(outputs, "[", 1, FUN.VALUE = character(1))
2727

28-
algorithm_outputs <- qgis_get_output_specs(algorithm)
28+
algorithm_outputs <- qgis_get_output_specs(algorithm, check_deprecation = FALSE)
2929

3030
outputs_list <- Map(
3131
qgis_parse_result_output,

man/qgis_show_help.Rd

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)