Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ export(as_qgis_argument)
export(assert_qgis)
export(assert_qgis_algorithm)
export(has_qgis)
export(is_macos)
export(is_qgis_default_value)
export(is_qgis_result)
export(is_qgis_tmp_file)
export(is_windows)
export(qgis_algorithms)
export(qgis_argument_spec)
export(qgis_argument_spec_by_name)
Expand All @@ -59,8 +57,7 @@ export(qgis_clean_arguments)
export(qgis_configure)
export(qgis_default_value)
export(qgis_description)
export(qgis_detect_macos)
export(qgis_detect_windows)
export(qgis_detect_paths)
export(qgis_dict_input)
export(qgis_disable_plugins)
export(qgis_enable_plugins)
Expand Down
4 changes: 2 additions & 2 deletions R/qgis-configure.R
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,9 @@ qgis_query_path <- function(quiet = FALSE) {
)

possible_locs <- if (is_macos()) {
qgis_detect_macos()
qgis_detect_macos_paths()
} else if (is_windows()) {
qgis_detect_windows()
qgis_detect_windows_paths()
}

if (length(possible_locs) == 0) {
Expand Down
29 changes: 17 additions & 12 deletions R/qgis-detect.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
#' Detect QGIS installations with 'qgis_process'
#'
#' @param drive_letter The drive letter on which to search. By default,
#' this is the same drive letter as the R executable.
#' this is the same drive letter as the R executable. Only relevant on
#' Windows, on other platforms the parameter is ignored.
#'
#' @return A character vector of possible paths to the QGIS executable.
#' @export
#'
#' @examples
#' if (is_windows()) qgis_detect_windows()
#' if (is_macos()) qgis_detect_macos()
#'
qgis_detect_windows <- function(drive_letter = strsplit(R.home(), ":")[[1]][1]) {
#' qgis_detect_paths()
#'
qgis_detect_paths <- function(drive_letter = strsplit(R.home(), ":")[[1]][1]) {
if (is_macos()){
return (qgis_detect_macos_paths())
}
else if (is_windows()) {
return (qgis_detect_windows_paths(drive_letter))
}
return ("qgis_process")
}

qgis_detect_windows_paths <- function(drive_letter = strsplit(R.home(), ":")[[1]][1]) {
if (!is_windows()) {
abort("Can't use `qgis_detect_windows()` on a non-windows platform.")
abort("Can't use `qgis_detect_windows_paths()` on a non-windows platform.")
}

bat_files <- c(
Expand All @@ -34,9 +45,7 @@ qgis_detect_windows <- function(drive_letter = strsplit(R.home(), ":")[[1]][1])
possible_locs_win[file.exists(possible_locs_win)]
}

#' @rdname qgis_detect_windows
#' @export
qgis_detect_macos <- function() {
qgis_detect_macos_paths <- function() {
if (!is_macos()) {
abort("Can't use `qgis_detect_macos()` on a non-MacOS platform.")
}
Expand All @@ -49,15 +58,11 @@ qgis_detect_macos <- function() {
possible_locs_mac[file.exists(possible_locs_mac)]
}

#' @rdname qgis_detect_windows
#' @export
is_macos <- function() {
(.Platform$OS.type == "unix") &&
identical(unname(Sys.info()["sysname"]), "Darwin")
}

#' @rdname qgis_detect_windows
#' @export
is_windows <- function() {
.Platform$OS.type == "windows"
}
22 changes: 7 additions & 15 deletions man/qgis_detect_windows.Rd → man/qgis_detect_paths.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/vignette_childs/_qgis_expressions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ The `load_layer()` approach since QGIS 3.30.0 avoids the need for a QGIS project

Now we can run the algorithm:

```{r eval=(package_version(strsplit(qgis_version(), "-")[[1]][1]) >= "3.30.0") && !is_windows()}
```{r eval=(package_version(strsplit(qgis_version(), "-")[[1]][1]) >= "3.30.0") && !qgisprocess:::is_windows()}
qgis_run_algorithm(
"native:fieldcalculator",
INPUT = longlake_depth_path,
Expand Down
3 changes: 1 addition & 2 deletions tests/platform-info.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ qgis_configure(use_cached_data = TRUE) # triggers reconfiguration if needed

has_qgis()

if (is_macos()) qgis_detect_macos()
if (is_windows()) qgis_detect_windows()
qgis_detect_paths()

if (has_qgis()) qgis_path()
if (has_qgis()) qgis_version()
Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test-qgis-detect.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
test_that("qgis_detect_macos() works", {
test_that("qgis_detect_macos_paths() works", {
if (is_macos()) {
expect_type(qgis_detect_macos(), "character")
expect_type(qgis_detect_macos_paths(), "character")
} else {
expect_error(qgis_detect_macos(), "non-MacOS")
expect_error(qgis_detect_macos_paths(), "non-MacOS")
}
})

test_that("qgis_detect_windows() works", {
test_that("qgis_detect_windows_paths() works", {
if (is_windows()) {
expect_type(qgis_detect_windows(), "character")
expect_type(qgis_detect_windows_paths(), "character")
} else {
expect_error(qgis_detect_windows(), "non-windows")
expect_error(qgis_detect_windows_paths(), "non-windows")
}
})