From 2bd5d8c179c2c038e54635f701544c6d0862f2f4 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 5 Aug 2024 14:15:23 +0200 Subject: [PATCH] add the option to pass wait to system2 --- DESCRIPTION | 2 +- R/node.R | 10 ++++++---- man/exec_flowr.Rd | 9 ++++++++- man/exec_node_command.Rd | 5 ++++- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 26b8fc8..56f3f6f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -8,7 +8,7 @@ Description: Interact with flowR directly from R. License: GPL-3 + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Imports: digest, jsonlite, diff --git a/R/node.R b/R/node.R index 5cc1f5b..9f0239d 100644 --- a/R/node.R +++ b/R/node.R @@ -68,13 +68,14 @@ install_flowr <- function(flowr_ver, verbose = FALSE, base_dir = get_default_nod #' @param args The arguments to pass to the flowR CLI, as a character. #' @param verbose Whether to print out information about the commands being executed. #' @param base_dir The base directory that Node and flowR were installed in. By default, this uses the package's installation directory through [get_default_node_base_dir()]. +#' @param wait Whether to wait for the command to finish before returning. #' @return The return value of the [exec_node_command()] call. #' #' @export -exec_flowr <- function(args, verbose = FALSE, base_dir = get_default_node_base_dir()) { +exec_flowr <- function(args, verbose = FALSE, base_dir = get_default_node_base_dir(), wait = TRUE) { # we installed flowr globally (see above) in the scope of our local node installation, so we can find it here flowr_path <- file.path(get_node_exe_dir(base_dir), "node_modules", "@eagleoutice", "flowr", "cli", "flowr.js") - exec_node_command("node", paste(flowr_path, args), verbose, base_dir) + exec_node_command("node", paste(flowr_path, args), verbose, base_dir, wait) } #' Executes the given Node subcommand in the given arguments in the given directory. @@ -84,17 +85,18 @@ exec_flowr <- function(args, verbose = FALSE, base_dir = get_default_node_base_d #' @param args The arguments to pass to the Node command, as a character. #' @param verbose Whether to print out information about the commands being executed. #' @param base_dir The base directory that Node was installed in. By default, this uses the package's installation directory through [get_default_node_base_dir()]. +#' @param wait Whether to wait for the command to finish before returning. #' @return The return value of the system2 call. #' #' @export -exec_node_command <- function(app = c("node", "npm", "npx"), args, verbose = FALSE, base_dir = get_default_node_base_dir()) { +exec_node_command <- function(app = c("node", "npm", "npx"), args, verbose = FALSE, base_dir = get_default_node_base_dir(), wait = TRUE) { # linux/mac have binaries in the bin subdirectory, windows has node.exe and npm/npx.cmd in the root, bleh path <- if (get_os() == "win") paste0(app, if (app == "node") ".exe" else ".cmd") else file.path("bin", app) cmd <- file.path(get_node_exe_dir(base_dir), path) if (verbose) { print(paste0("Executing ", cmd, " ", paste0(args, collapse = " "))) } - return(system2(cmd, args)) + return(system2(cmd, args, wait = wait)) } #' Returns the default node base directory to use when installing Node, which is the directory that the package with the given name is installed in. diff --git a/man/exec_flowr.Rd b/man/exec_flowr.Rd index 2674155..52ca033 100644 --- a/man/exec_flowr.Rd +++ b/man/exec_flowr.Rd @@ -5,7 +5,12 @@ \title{Executes a local version of the flowR CLI with the given arguments in the given directory. This function expects Node and flowR to have been installed using \code{\link[=install_node]{install_node()}} and \code{\link[=install_flowr]{install_flowr()}} prior.} \usage{ -exec_flowr(args, verbose = FALSE, base_dir = get_default_node_base_dir()) +exec_flowr( + args, + verbose = FALSE, + base_dir = get_default_node_base_dir(), + wait = TRUE +) } \arguments{ \item{args}{The arguments to pass to the flowR CLI, as a character.} @@ -13,6 +18,8 @@ exec_flowr(args, verbose = FALSE, base_dir = get_default_node_base_dir()) \item{verbose}{Whether to print out information about the commands being executed.} \item{base_dir}{The base directory that Node and flowR were installed in. By default, this uses the package's installation directory through \code{\link[=get_default_node_base_dir]{get_default_node_base_dir()}}.} + +\item{wait}{Whether to wait for the command to finish before returning.} } \value{ The return value of the \code{\link[=exec_node_command]{exec_node_command()}} call. diff --git a/man/exec_node_command.Rd b/man/exec_node_command.Rd index f16fa20..a9cbcea 100644 --- a/man/exec_node_command.Rd +++ b/man/exec_node_command.Rd @@ -9,7 +9,8 @@ exec_node_command( app = c("node", "npm", "npx"), args, verbose = FALSE, - base_dir = get_default_node_base_dir() + base_dir = get_default_node_base_dir(), + wait = TRUE ) } \arguments{ @@ -20,6 +21,8 @@ exec_node_command( \item{verbose}{Whether to print out information about the commands being executed.} \item{base_dir}{The base directory that Node was installed in. By default, this uses the package's installation directory through \code{\link[=get_default_node_base_dir]{get_default_node_base_dir()}}.} + +\item{wait}{Whether to wait for the command to finish before returning.} } \value{ The return value of the system2 call.