Skip to content

Commit

Permalink
as_qgis_argument(): add support for matrix objects (qgis_type matrix)
Browse files Browse the repository at this point in the history
  • Loading branch information
florisvdh committed Jun 9, 2023
1 parent e2ff228 commit e702c46
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ S3method(as_qgis_argument,crs)
S3method(as_qgis_argument,default)
S3method(as_qgis_argument,list)
S3method(as_qgis_argument,logical)
S3method(as_qgis_argument,matrix)
S3method(as_qgis_argument,numeric)
S3method(as_qgis_argument,qgis_default_value)
S3method(as_qgis_argument,qgis_dict_input)
Expand Down
18 changes: 18 additions & 0 deletions R/qgis-arguments.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ as_qgis_argument.character <- function(x, spec = qgis_argument_spec(),
x
)

if (!is.null(dim(result)) && max(dim(x)) > 1L && !use_json_input) NextMethod()

if (use_json_input) result else paste(result, collapse = ",")
}

Expand All @@ -272,10 +274,26 @@ as_qgis_argument.logical <- function(x, spec = qgis_argument_spec(),
if (use_json_input) x else paste0(x, collapse = ",")
}

#' @keywords internal
#' @export
as_qgis_argument.matrix <- function(x, spec = qgis_argument_spec(),
use_json_input = FALSE) {
# !is.na() is solely wrt unit tests that don't specify qgis_type
if (!is.na(spec$qgis_type) && spec$qgis_type == "matrix") {
if (is.numeric(x)) x <- base::as.numeric(t(x)) else {
x <- as.character(t(x))
}
} else if (!use_json_input) {
NextMethod()
}
if (use_json_input) x else paste0(x, collapse = ",")
}

#' @keywords internal
#' @export
as_qgis_argument.numeric <- function(x, spec = qgis_argument_spec(),
use_json_input = FALSE) {
if (!is.null(dim(x)) && max(dim(x)) > 1L && !use_json_input) NextMethod()
if (use_json_input) x else paste0(x, collapse = ",")
}

Expand Down

0 comments on commit e702c46

Please sign in to comment.