From 3cc924de4720f3e80b6ce4713d233e706f519b83 Mon Sep 17 00:00:00 2001 From: hsonne Date: Tue, 29 Aug 2023 19:04:04 +0200 Subject: [PATCH 01/25] Add functions to determine system architecture --- R/run_abimo.R | 2 +- R/utils.R | 45 +++++++++++++++++++++++++++++++++++++ vignettes/running-abimo.Rmd | 5 +---- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/R/run_abimo.R b/R/run_abimo.R index ab685ed..56470fa 100644 --- a/R/run_abimo.R +++ b/R/run_abimo.R @@ -99,7 +99,7 @@ full_quoted_path <- function(x) x <- path.expand(x) # Convert slashes to backslashes on windows - if (Sys.info()["sysname"] == "Windows") { + if (on_windows()) { x <- kwb.utils::windowsPath(x) } diff --git a/R/utils.R b/R/utils.R index d5cc71f..2713ebc 100644 --- a/R/utils.R +++ b/R/utils.R @@ -5,3 +5,48 @@ #' @inheritParams kwb.utils::extdataFile #' @export extdata_file <- kwb.utils::createFunctionExtdataFile("kwb.abimo") + +# get_architecture_suffix ------------------------------------------------------ +get_architecture_suffix <- function() +{ + if (on_windows() && on_64bit()) { + return("win64") + } + + if (!on_windows() && on_64bit()) { + return("unix64") + } + + kwb.utils::printIf(TRUE, .Platform) + kwb.utils::printIf(TRUE, R.version) + + stop( + "Unexpected platform type and architecture. ", + "Expected: one of 'win64', 'unix64'", + call. = FALSE + ) +} + +# get_os_architecture ---------------------------------------------------------- +get_os_architecture <- function() +{ + kwb.utils::selectElements(R.version, "arch") +} + +# get_os_type ------------------------------------------------------------------ +get_os_type <- function() +{ + kwb.utils::selectElements(.Platform, "OS.type") +} + +# on_64bit --------------------------------------------------------------------- +on_64bit <- function() +{ + get_os_architecture() == "x86_64" +} + +# on_windows ------------------------------------------------------------------- +on_windows <- function() +{ + get_os_type() == "windows" +} diff --git a/vignettes/running-abimo.Rmd b/vignettes/running-abimo.Rmd index 9b55b95..4a9fa14 100644 --- a/vignettes/running-abimo.Rmd +++ b/vignettes/running-abimo.Rmd @@ -10,14 +10,11 @@ editor_options: --- ```{r, include = FALSE} -is_windows <- .Platform$OS.type == "windows" - knitr::opts_chunk$set( collapse = TRUE, comment = "#>", - eval = is_windows + eval = kwb.abimo:::on_windows() ) -is_windows <- .Platform$OS.type == "windows" ``` This vignette aims at demonstrating how to work with the kwb.abimo package. From 9316919681310711b3e67e7c558894741c82eb5f Mon Sep 17 00:00:00 2001 From: hsonne Date: Tue, 29 Aug 2023 19:04:39 +0200 Subject: [PATCH 02/25] Start supporting Unix version of Abimo --- R/helpers.R | 6 +++++- R/install_abimo.R | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/R/helpers.R b/R/helpers.R index 9567772..9a9226a 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -5,7 +5,11 @@ NULL # abimo_binary ----------------------------------------------------------------- abimo_binary <- function(tag = latest_abimo_version()) { - file.path(extdata_file(), paste0("abimo_", tag, "_win64"), "Abimo.exe") + file.path( + extdata_file(), + paste0("abimo_", tag, "_", get_architecture_suffix()), + ifelse(on_windows, "Abimo.exe", "Abimo") + ) } # abimo_help ------------------------------------------------------------------- diff --git a/R/install_abimo.R b/R/install_abimo.R index c411a1e..cb2ac49 100644 --- a/R/install_abimo.R +++ b/R/install_abimo.R @@ -2,7 +2,10 @@ #' @importFrom archive archive_extract #' @importFrom kwb.utils catAndRun createDirectory -install_abimo <- function(tag = latest_abimo_version(), arch = "win64") +install_abimo <- function( + tag = latest_abimo_version(), + arch = get_architecture_suffix() +) { if (arch != "win64") { stop("Currently, the abimo executable is only available for win64") From ac4ee0ad9fe2a974d97678617b58512a18eff49d Mon Sep 17 00:00:00 2001 From: hsonne Date: Tue, 29 Aug 2023 19:08:27 +0200 Subject: [PATCH 03/25] Fix bug by actually calling the function --- R/helpers.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/helpers.R b/R/helpers.R index 9a9226a..d6a159d 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -8,7 +8,7 @@ abimo_binary <- function(tag = latest_abimo_version()) file.path( extdata_file(), paste0("abimo_", tag, "_", get_architecture_suffix()), - ifelse(on_windows, "Abimo.exe", "Abimo") + ifelse(on_windows(), "Abimo.exe", "Abimo") ) } From 4fecb8a6b59bc25a9c3cc4f1c8022b6e148e149b Mon Sep 17 00:00:00 2001 From: hsonne Date: Tue, 29 Aug 2023 19:44:52 +0200 Subject: [PATCH 04/25] Allow installation for unix architecture --- R/install_abimo.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/install_abimo.R b/R/install_abimo.R index cb2ac49..f0f3e1b 100644 --- a/R/install_abimo.R +++ b/R/install_abimo.R @@ -7,8 +7,12 @@ install_abimo <- function( arch = get_architecture_suffix() ) { - if (arch != "win64") { - stop("Currently, the abimo executable is only available for win64") + if (!arch %in% c("win64", "unix64")) { + stop( + "Currently, the abimo executable is only available for win64 or unix64", + call. = FALSE + + ) } exdir <- dirname(abimo_binary(tag)) From 7ec1a3bc7f905bc7fa2fcd6b147bf951fef7f2e9 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sat, 2 Sep 2023 06:16:45 +0200 Subject: [PATCH 05/25] Allow to pass args to run_abimo_command_line() --- R/helpers.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/helpers.R b/R/helpers.R index d6a159d..3e9c71c 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -13,15 +13,15 @@ abimo_binary <- function(tag = latest_abimo_version()) } # abimo_help ------------------------------------------------------------------- -abimo_help <- function() +abimo_help <- function(...) { - run_abimo_command_line("--help") + run_abimo_command_line("--help", ...) } # abimo_version ---------------------------------------------------------------- -abimo_version <- function() +abimo_version <- function(...) { - run_abimo_command_line("--version") + run_abimo_command_line("--version", ...) } # appendSubToFile -------------------------------------------------------------- From 4a4d171aebbab277e35e0edf43676a6fbc44489e Mon Sep 17 00:00:00 2001 From: hsonne Date: Sat, 2 Sep 2023 06:18:39 +0200 Subject: [PATCH 06/25] Modify/move/reuse check_abimo_binary() --- R/helpers.R | 18 ++++++++++++++++++ R/run_abimo.R | 16 +--------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/R/helpers.R b/R/helpers.R index 3e9c71c..e9ff58d 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -45,6 +45,22 @@ appendSubToFile <- function (filename) writeBin(as.raw(0x1A), con) } +# check_abimo_binary ----------------------------------------------------------- +check_abimo_binary <- function(tag = latest_abimo_version()) +{ + file <- abimo_binary(tag) + + if (!file.exists(file)) { + install_abimo(tag) + } + + if (!file.exists(file)) { + kwb.utils::stopFormatted( + "Could not install or find Abimo (no such file: %s)", file + ) + } +} + # default_config ----------------------------------------------------------------- #' Default ABIMO config.xml path @@ -101,6 +117,8 @@ latest_abimo_version <- function() #' @export run_abimo_command_line <- function(args, tag = latest_abimo_version()) { + check_abimo_binary(tag) + output <- system2(abimo_binary(tag), args = args, stdout = TRUE) output diff --git a/R/run_abimo.R b/R/run_abimo.R index 56470fa..a148d3f 100644 --- a/R/run_abimo.R +++ b/R/run_abimo.R @@ -52,9 +52,7 @@ run_abimo <- function( config_file <- config$save(file = file.path(tempdir(), file_name)) } - if (!check_abimo_binary(tag)) { - stop("Could not install Abimo!") - } + check_abimo_binary(tag) output_file <- kwb.utils::defaultIfNULL( output_file, default_output_file(input_file) @@ -72,18 +70,6 @@ run_abimo <- function( foreign::read.dbf(output_file) } -# check_abimo_binary ----------------------------------------------------------- -check_abimo_binary <- function(tag = latest_abimo_version()) -{ - file <- abimo_binary(tag) - - if (file.exists(file)) { - return(TRUE) - } - - file.exists(install_abimo(tag)) -} - # default_output_file ---------------------------------------------------------- #' @importFrom kwb.utils replaceFileExtension From 6f89184775f4c4be0ff507dbb2b0e02debe26846 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sat, 2 Sep 2023 06:20:06 +0200 Subject: [PATCH 07/25] Simplify architecture strings (expect 64 bit!) --- R/install_abimo.R | 8 ++++++-- R/utils.R | 37 ++++++++++--------------------------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/R/install_abimo.R b/R/install_abimo.R index f0f3e1b..a38e648 100644 --- a/R/install_abimo.R +++ b/R/install_abimo.R @@ -7,9 +7,13 @@ install_abimo <- function( arch = get_architecture_suffix() ) { - if (!arch %in% c("win64", "unix64")) { + expected_architectures <- c("windows", "linux", "macos") + + if (!arch %in% expected_architectures) { stop( - "Currently, the abimo executable is only available for win64 or unix64", + "Currently, the abimo executable is only available for one of these ", + "'architectures': ", + kwb.utils::stringList(expected_architectures), call. = FALSE ) diff --git a/R/utils.R b/R/utils.R index 2713ebc..236041c 100644 --- a/R/utils.R +++ b/R/utils.R @@ -9,44 +9,27 @@ extdata_file <- kwb.utils::createFunctionExtdataFile("kwb.abimo") # get_architecture_suffix ------------------------------------------------------ get_architecture_suffix <- function() { - if (on_windows() && on_64bit()) { - return("win64") - } - - if (!on_windows() && on_64bit()) { - return("unix64") - } - - kwb.utils::printIf(TRUE, .Platform) - kwb.utils::printIf(TRUE, R.version) - - stop( - "Unexpected platform type and architecture. ", - "Expected: one of 'win64', 'unix64'", - call. = FALSE + suffixes <- list( + Linux = "linux", + Darwin = "macos", + Windows = "windows" ) -} -# get_os_architecture ---------------------------------------------------------- -get_os_architecture <- function() -{ - kwb.utils::selectElements(R.version, "arch") + kwb.utils::selectElements(suffixes, get_os_type()) } # get_os_type ------------------------------------------------------------------ get_os_type <- function() { - kwb.utils::selectElements(.Platform, "OS.type") -} + os_type <- Sys.info()[["sysname"]] -# on_64bit --------------------------------------------------------------------- -on_64bit <- function() -{ - get_os_architecture() == "x86_64" + stopifnot(os_type %in% c("Windows", "Linux", "Darwin")) + + os_type } # on_windows ------------------------------------------------------------------- on_windows <- function() { - get_os_type() == "windows" + get_os_type() == "Windows" } From f3ebcd251dd5ca4fff39d8e81ea637e14ef1686e Mon Sep 17 00:00:00 2001 From: hsonne Date: Sat, 2 Sep 2023 06:30:59 +0200 Subject: [PATCH 08/25] Try to build vignette on Linux/macOS as well --- vignettes/running-abimo.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/running-abimo.Rmd b/vignettes/running-abimo.Rmd index 4a9fa14..853d5f3 100644 --- a/vignettes/running-abimo.Rmd +++ b/vignettes/running-abimo.Rmd @@ -13,7 +13,7 @@ editor_options: knitr::opts_chunk$set( collapse = TRUE, comment = "#>", - eval = kwb.abimo:::on_windows() + eval = TRUE # kwb.abimo:::on_windows() ) ``` From 5c011cde5b23da054bc6cb921fcaa43f5a96d1c2 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sat, 2 Sep 2023 07:07:18 +0200 Subject: [PATCH 09/25] Consider executable's ".app" extension on macOS and add on_linux(), on_macos() --- R/helpers.R | 4 ++-- R/utils.R | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/R/helpers.R b/R/helpers.R index e9ff58d..41f5c76 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -50,11 +50,11 @@ check_abimo_binary <- function(tag = latest_abimo_version()) { file <- abimo_binary(tag) - if (!file.exists(file)) { + if (!executable_exists(file)) { install_abimo(tag) } - if (!file.exists(file)) { + if (!executable_exists(file)) { kwb.utils::stopFormatted( "Could not install or find Abimo (no such file: %s)", file ) diff --git a/R/utils.R b/R/utils.R index 236041c..30d5e63 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,3 +1,13 @@ +# executable_exists ------------------------------------------------------------ +executable_exists <- function(file) +{ + if (on_macos()) { + file <- paste0(file, ".app") + } + + file.exists(file) +} + # extdata_file ----------------------------------------------------------------- #' Get Path to File in This Package @@ -28,6 +38,18 @@ get_os_type <- function() os_type } +# on_linux --------------------------------------------------------------------- +on_linux <- function() +{ + get_os_type() == "Linux" +} + +# on_macos --------------------------------------------------------------------- +on_macos <- function() +{ + get_os_type() == "Darwin" +} + # on_windows ------------------------------------------------------------------- on_windows <- function() { From 71c96464e49009189bcbaf3e82f8d2028384570f Mon Sep 17 00:00:00 2001 From: hsonne Date: Sat, 2 Sep 2023 07:34:08 +0200 Subject: [PATCH 10/25] Try to call Abimo on macOS --- R/helpers.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/helpers.R b/R/helpers.R index 41f5c76..eb838d4 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -119,7 +119,13 @@ run_abimo_command_line <- function(args, tag = latest_abimo_version()) { check_abimo_binary(tag) - output <- system2(abimo_binary(tag), args = args, stdout = TRUE) + command <- abimo_binary(tag) + + if (on_macos()) { + command <- paste0("open ", command, ".app") + } + + output <- system2(command, args = args, stdout = TRUE) output } From 8c25454f4e5fbca375db0b1ca53666dd25a6c3a2 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sat, 2 Sep 2023 08:12:51 +0200 Subject: [PATCH 11/25] Let abimo_binary() return system dependent path --- R/helpers.R | 16 ++++++++++------ R/utils.R | 16 ++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/R/helpers.R b/R/helpers.R index eb838d4..7d8a302 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -8,7 +8,7 @@ abimo_binary <- function(tag = latest_abimo_version()) file.path( extdata_file(), paste0("abimo_", tag, "_", get_architecture_suffix()), - ifelse(on_windows(), "Abimo.exe", "Abimo") + append_extension_for_executable("Abimo") ) } @@ -50,11 +50,11 @@ check_abimo_binary <- function(tag = latest_abimo_version()) { file <- abimo_binary(tag) - if (!executable_exists(file)) { + if (!file.exists(file)) { install_abimo(tag) } - if (!executable_exists(file)) { + if (!file.exists(file)) { kwb.utils::stopFormatted( "Could not install or find Abimo (no such file: %s)", file ) @@ -119,10 +119,14 @@ run_abimo_command_line <- function(args, tag = latest_abimo_version()) { check_abimo_binary(tag) - command <- abimo_binary(tag) + path <- abimo_binary(tag) - if (on_macos()) { - command <- paste0("open ", command, ".app") + print.data.frame(fs::dir_info(path, recurse = TRUE)) + + command <- if (on_macos()) { + paste0("open ", path) + } else { + path } output <- system2(command, args = args, stdout = TRUE) diff --git a/R/utils.R b/R/utils.R index 30d5e63..e87add9 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,11 +1,15 @@ -# executable_exists ------------------------------------------------------------ -executable_exists <- function(file) +# append_extension_for_executable ---------------------------------------------- +append_extension_for_executable <- function(x) { - if (on_macos()) { - file <- paste0(file, ".app") - } + extensions <- list( + Windows = ".exe", + Linux = "", + Darwin = ".app" + ) + + extension <- kwb.utils::selectElements(extensions, get_os_type()) - file.exists(file) + paste0(x, extension) } # extdata_file ----------------------------------------------------------------- From d54540b1f8cecd568ac0655ccf3652910f6c3179 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sat, 2 Sep 2023 08:24:55 +0200 Subject: [PATCH 12/25] Try to debug error on macOS --- R/helpers.R | 15 +++++++++------ R/run_abimo.R | 2 -- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/R/helpers.R b/R/helpers.R index 7d8a302..4dfffd1 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -59,6 +59,8 @@ check_abimo_binary <- function(tag = latest_abimo_version()) "Could not install or find Abimo (no such file: %s)", file ) } + + file } # default_config ----------------------------------------------------------------- @@ -117,11 +119,7 @@ latest_abimo_version <- function() #' @export run_abimo_command_line <- function(args, tag = latest_abimo_version()) { - check_abimo_binary(tag) - - path <- abimo_binary(tag) - - print.data.frame(fs::dir_info(path, recurse = TRUE)) + path <- check_abimo_binary(tag) command <- if (on_macos()) { paste0("open ", path) @@ -129,7 +127,12 @@ run_abimo_command_line <- function(args, tag = latest_abimo_version()) path } - output <- system2(command, args = args, stdout = TRUE) + output <- try(system2(command, args = args, stdout = TRUE)) + + if (kwb.utils::isTryError(output)) { + print.data.frame(fs::dir_info(path, recurse = TRUE)) + stop("system2() failed.") + } output } diff --git a/R/run_abimo.R b/R/run_abimo.R index a148d3f..bb2b414 100644 --- a/R/run_abimo.R +++ b/R/run_abimo.R @@ -52,8 +52,6 @@ run_abimo <- function( config_file <- config$save(file = file.path(tempdir(), file_name)) } - check_abimo_binary(tag) - output_file <- kwb.utils::defaultIfNULL( output_file, default_output_file(input_file) ) From dbe73acd8a555ac761ffbbed054873fb24e5a96d Mon Sep 17 00:00:00 2001 From: hsonne Date: Sat, 2 Sep 2023 08:31:19 +0200 Subject: [PATCH 13/25] Output file list in error message --- DESCRIPTION | 1 + R/helpers.R | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index aec30f7..fd71b77 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -31,6 +31,7 @@ BugReports: https://github.com/KWB-R/kwb.abimo/issues Imports: archive, foreign, + fs, gh, gridExtra, kwb.utils, diff --git a/R/helpers.R b/R/helpers.R index 4dfffd1..2daf621 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -130,8 +130,10 @@ run_abimo_command_line <- function(args, tag = latest_abimo_version()) output <- try(system2(command, args = args, stdout = TRUE)) if (kwb.utils::isTryError(output)) { - print.data.frame(fs::dir_info(path, recurse = TRUE)) - stop("system2() failed.") + stop( + "system2() failed. Files below ", path, ":\n", + capture.output(print.data.frame(fs::dir_info(path, recurse = TRUE))) + ) } output From 484c2859d841d1ecb6b2af63534b4b6a1195a80d Mon Sep 17 00:00:00 2001 From: hsonne Date: Sat, 2 Sep 2023 08:46:04 +0200 Subject: [PATCH 14/25] Simplify/shorten output of file info --- DESCRIPTION | 1 - R/helpers.R | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index fd71b77..aec30f7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -31,7 +31,6 @@ BugReports: https://github.com/KWB-R/kwb.abimo/issues Imports: archive, foreign, - fs, gh, gridExtra, kwb.utils, diff --git a/R/helpers.R b/R/helpers.R index 2daf621..e9686b7 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -132,7 +132,7 @@ run_abimo_command_line <- function(args, tag = latest_abimo_version()) if (kwb.utils::isTryError(output)) { stop( "system2() failed. Files below ", path, ":\n", - capture.output(print.data.frame(fs::dir_info(path, recurse = TRUE))) + capture.output(dir(path, recurse = TRUE)) ) } From c3187a193b255ba9a44a791716faac74203a089c Mon Sep 17 00:00:00 2001 From: hsonne Date: Sat, 2 Sep 2023 08:50:21 +0200 Subject: [PATCH 15/25] Fix argument name --- R/helpers.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/helpers.R b/R/helpers.R index e9686b7..6866b3c 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -132,7 +132,7 @@ run_abimo_command_line <- function(args, tag = latest_abimo_version()) if (kwb.utils::isTryError(output)) { stop( "system2() failed. Files below ", path, ":\n", - capture.output(dir(path, recurse = TRUE)) + capture.output(dir(path, recursive = TRUE)) ) } From be7eaf1c4a1ce10f3ec7978d18add5b304063aa0 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sat, 2 Sep 2023 09:18:37 +0200 Subject: [PATCH 16/25] Try again to run Abimo on macOS --- R/helpers.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/R/helpers.R b/R/helpers.R index 6866b3c..0d08891 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -121,10 +121,11 @@ run_abimo_command_line <- function(args, tag = latest_abimo_version()) { path <- check_abimo_binary(tag) - command <- if (on_macos()) { - paste0("open ", path) + if (on_macos()) { + command <- "open" + args <- c(path, args) } else { - path + command <- path } output <- try(system2(command, args = args, stdout = TRUE)) @@ -132,7 +133,7 @@ run_abimo_command_line <- function(args, tag = latest_abimo_version()) if (kwb.utils::isTryError(output)) { stop( "system2() failed. Files below ", path, ":\n", - capture.output(dir(path, recursive = TRUE)) + paste(dir(path, recursive = TRUE), collapse = "\n") ) } From 01217a8eabbfe1f9e1fa3482364e0bdc14fdaeb5 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sat, 2 Sep 2023 09:27:58 +0200 Subject: [PATCH 17/25] Try to run Abimo on macOS using --args --- R/helpers.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/helpers.R b/R/helpers.R index 0d08891..62587b5 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -123,7 +123,7 @@ run_abimo_command_line <- function(args, tag = latest_abimo_version()) if (on_macos()) { command <- "open" - args <- c(path, args) + args <- c(path, "--args", args) } else { command <- path } From 3be94b88ef12c1445d27d8049783feccc7186a76 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sat, 2 Sep 2023 09:27:58 +0200 Subject: [PATCH 18/25] Try to specify the path to the app with -a --- R/helpers.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/helpers.R b/R/helpers.R index 0d08891..ce59a78 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -123,7 +123,7 @@ run_abimo_command_line <- function(args, tag = latest_abimo_version()) if (on_macos()) { command <- "open" - args <- c(path, args) + args <- c("-a", path, "--args", args) } else { command <- path } From f02301aec247fd6b12c7f19f7a660be56be927b9 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sat, 2 Sep 2023 10:06:04 +0200 Subject: [PATCH 19/25] Call executable directly (in strange subdir) --- R/helpers.R | 17 ++++++++--------- R/utils.R | 14 -------------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/R/helpers.R b/R/helpers.R index ce59a78..44275af 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -5,10 +5,16 @@ NULL # abimo_binary ----------------------------------------------------------------- abimo_binary <- function(tag = latest_abimo_version()) { + formats <- list( + Windows = "%s.exe", + Linux = "%s", + Darwin = "%s.app/Contents/MacOS/GNUSparseFile.0/%s" + ) + file.path( extdata_file(), paste0("abimo_", tag, "_", get_architecture_suffix()), - append_extension_for_executable("Abimo") + sprintf(kwb.utils::selectElements(formats, get_os_type()), "Abimo") ) } @@ -119,14 +125,7 @@ latest_abimo_version <- function() #' @export run_abimo_command_line <- function(args, tag = latest_abimo_version()) { - path <- check_abimo_binary(tag) - - if (on_macos()) { - command <- "open" - args <- c("-a", path, "--args", args) - } else { - command <- path - } + command <- check_abimo_binary(tag) output <- try(system2(command, args = args, stdout = TRUE)) diff --git a/R/utils.R b/R/utils.R index e87add9..e3cc9a5 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,17 +1,3 @@ -# append_extension_for_executable ---------------------------------------------- -append_extension_for_executable <- function(x) -{ - extensions <- list( - Windows = ".exe", - Linux = "", - Darwin = ".app" - ) - - extension <- kwb.utils::selectElements(extensions, get_os_type()) - - paste0(x, extension) -} - # extdata_file ----------------------------------------------------------------- #' Get Path to File in This Package From 3a24c0a4efd81268415ca39fac9ef13157d8f585 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sat, 2 Sep 2023 14:43:56 +0200 Subject: [PATCH 20/25] Run abimo_version() in vignette to check if the error "too few arguments" occurs also with this function --- vignettes/running-abimo.Rmd | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vignettes/running-abimo.Rmd b/vignettes/running-abimo.Rmd index 853d5f3..143918b 100644 --- a/vignettes/running-abimo.Rmd +++ b/vignettes/running-abimo.Rmd @@ -19,6 +19,12 @@ knitr::opts_chunk$set( This vignette aims at demonstrating how to work with the kwb.abimo package. +## Install Abimo and check the version + +```{r basic-run} +kwb.abimo:::abimo_version() +``` + ## Basic model run ```{r basic-run} From 35e2f3cc5997fa880e5fe01b4862d355c54daedc Mon Sep 17 00:00:00 2001 From: hsonne Date: Sat, 2 Sep 2023 14:47:02 +0200 Subject: [PATCH 21/25] Use unique chunk labels --- vignettes/running-abimo.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/running-abimo.Rmd b/vignettes/running-abimo.Rmd index 143918b..e071093 100644 --- a/vignettes/running-abimo.Rmd +++ b/vignettes/running-abimo.Rmd @@ -21,7 +21,7 @@ This vignette aims at demonstrating how to work with the kwb.abimo package. ## Install Abimo and check the version -```{r basic-run} +```{r install-abimo} kwb.abimo:::abimo_version() ``` From 38e0cd569fedae23511a7d35cd922397e9068fc1 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sat, 2 Sep 2023 14:57:47 +0200 Subject: [PATCH 22/25] Try to use ubuntu-latest --- .github/workflows/R-CMD-check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index c579205..aa4eabc 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -23,7 +23,7 @@ jobs: matrix: config: - {os: macOS-latest, r: 'release'} - - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + - {os: ubuntu-latest, r: 'release'} - {os: windows-latest, r: 'devel'} - {os: windows-latest, r: 'oldrel'} - {os: windows-latest, r: 'release'} From 4229135b7013f4baa7229409ab99062144fc326d Mon Sep 17 00:00:00 2001 From: hsonne Date: Sat, 2 Sep 2023 15:19:43 +0200 Subject: [PATCH 23/25] Fix bug, add single statements for debugging --- R/helpers.R | 2 +- vignettes/running-abimo.Rmd | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/R/helpers.R b/R/helpers.R index 44275af..2500507 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -131,7 +131,7 @@ run_abimo_command_line <- function(args, tag = latest_abimo_version()) if (kwb.utils::isTryError(output)) { stop( - "system2() failed. Files below ", path, ":\n", + "system2() failed. Files below ", dirname(command), ":\n", paste(dir(path, recursive = TRUE), collapse = "\n") ) } diff --git a/vignettes/running-abimo.Rmd b/vignettes/running-abimo.Rmd index e071093..9540d79 100644 --- a/vignettes/running-abimo.Rmd +++ b/vignettes/running-abimo.Rmd @@ -21,6 +21,18 @@ This vignette aims at demonstrating how to work with the kwb.abimo package. ## Install Abimo and check the version +```{r} +tag <- kwb.abimo:::latest_abimo_version() +``` + +```{r} +command <- kwb.abimo:::check_abimo_binary(tag) +``` + +```{r} +output <- try(system2(command, args = "--version", stdout = TRUE)) +``` + ```{r install-abimo} kwb.abimo:::abimo_version() ``` From 25f239d776e0ff543befed577fc2fa466f522d61 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sat, 2 Sep 2023 15:36:06 +0200 Subject: [PATCH 24/25] Fix bug (argument to sprintf() was missing) --- R/helpers.R | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/R/helpers.R b/R/helpers.R index 2500507..4623ade 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -5,16 +5,18 @@ NULL # abimo_binary ----------------------------------------------------------------- abimo_binary <- function(tag = latest_abimo_version()) { - formats <- list( - Windows = "%s.exe", - Linux = "%s", - Darwin = "%s.app/Contents/MacOS/GNUSparseFile.0/%s" + name <- "Abimo" + + executables <- list( + Windows = paste0(name, ".exe"), + Linux = name, + Darwin = paste0(name, ".app/Contents/MacOS/GNUSparseFile.0/", name) ) file.path( extdata_file(), paste0("abimo_", tag, "_", get_architecture_suffix()), - sprintf(kwb.utils::selectElements(formats, get_os_type()), "Abimo") + kwb.utils::selectElements(executables, get_os_type()) ) } From b9b8a36de99670a3f6ffaf4a6cb33b935705e1cb Mon Sep 17 00:00:00 2001 From: hsonne Date: Wed, 27 Sep 2023 10:55:20 +0200 Subject: [PATCH 25/25] Fix conflict --- R/install_abimo.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R/install_abimo.R b/R/install_abimo.R index 43f4cbb..e940561 100644 --- a/R/install_abimo.R +++ b/R/install_abimo.R @@ -4,7 +4,8 @@ #' @importFrom kwb.utils catAndRun createDirectory install_abimo <- function( tag = latest_abimo_version(), - arch = get_architecture_suffix() + arch = get_architecture_suffix(), + ... ) { expected_architectures <- c("windows", "linux", "macos") @@ -27,7 +28,8 @@ install_abimo <- function( zip_files <- download_assets( repo = "KWB-R/abimo", tag = tag, - pattern = sprintf("abimo_%s_%s\\.", tag, arch) + pattern = sprintf("abimo_%s_%s\\.", tag, arch), + ... ) stopifnot(length(zip_files) == 1L)