From a15b1480af3dfb2993d5e89e4e9d168d0dd91c2c Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Wed, 9 Aug 2023 19:20:59 +0200 Subject: [PATCH] change order of args; fix exec cmd --- R/find_rev.R | 18 ++++++++++-------- dev/build_envs.Rmd | 18 ++++++++++-------- man/nix_build.Rd | 15 ++++++++------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/R/find_rev.R b/R/find_rev.R index 2f50acf8..dd197af1 100644 --- a/R/find_rev.R +++ b/R/find_rev.R @@ -390,21 +390,23 @@ USE_RSTUDIO}; #' Invoke shell command `nix-build` from an R session -#' @param exec_mode Either `"blocking"` (default) or `"non-blocking`. This -#' will either block the R session while the `nix-build` shell command is -#' executed, or run `nix-build` in the background ("non-blocking"). #' @param nix_file File path to the `default.nix` file. The default is #' a `default.nix` file in the current working directory of the current R #' session. -#' @return invisible +#' @param exec_mode Either `"blocking"` (default) or `"non-blocking`. This +#' will either block the R session while the `nix-build` shell command is +#' executed, or run `nix-build` in the background ("non-blocking"). +#' @return integer of the process ID (PID) of `nix-build` shell command +#' launched. #' @export -nix_build <- function(exec_mode = c("blocking", "non-blocking"), - nix_file = file.path("default.nix")) { +nix_build <- function(nix_file = file.path("default.nix"), + exec_mode = c("blocking", "non-blocking")) { + stopifnot(is.character(nix_file)) exec_mode <- match.arg(exec_mode) proc <- switch(exec_mode, - "blocking" = sys::exec_wait(cmd = "nix-build"), - "non-blocking" = sys::exec_background(cmd = "nix-build"), + "blocking" = sys::exec_wait("nix-build", nix_file), + "non-blocking" = sys::exec_background("nix-build", nix_file), stop('invalid `exec_mode`. Either use "blocking" or "non-blocking"') ) diff --git a/dev/build_envs.Rmd b/dev/build_envs.Rmd index 00d0b66e..eaa3ccb8 100644 --- a/dev/build_envs.Rmd +++ b/dev/build_envs.Rmd @@ -476,21 +476,23 @@ session. ```{r function-nix_build} #' Invoke shell command `nix-build` from an R session -#' @param exec_mode Either `"blocking"` (default) or `"non-blocking`. This -#' will either block the R session while the `nix-build` shell command is -#' executed, or run `nix-build` in the background ("non-blocking"). #' @param nix_file File path to the `default.nix` file. The default is #' a `default.nix` file in the current working directory of the current R #' session. -#' @return invisible +#' @param exec_mode Either `"blocking"` (default) or `"non-blocking`. This +#' will either block the R session while the `nix-build` shell command is +#' executed, or run `nix-build` in the background ("non-blocking"). +#' @return integer of the process ID (PID) of `nix-build` shell command +#' launched. #' @export -nix_build <- function(exec_mode = c("blocking", "non-blocking"), - nix_file = file.path("default.nix")) { +nix_build <- function(nix_file = file.path("default.nix"), + exec_mode = c("blocking", "non-blocking")) { + stopifnot(is.character(nix_file)) exec_mode <- match.arg(exec_mode) proc <- switch(exec_mode, - "blocking" = sys::exec_wait(cmd = "nix-build"), - "non-blocking" = sys::exec_background(cmd = "nix-build"), + "blocking" = sys::exec_wait("nix-build", nix_file), + "non-blocking" = sys::exec_background("nix-build", nix_file), stop('invalid `exec_mode`. Either use "blocking" or "non-blocking"') ) diff --git a/man/nix_build.Rd b/man/nix_build.Rd index 3c6bed09..b5a46411 100644 --- a/man/nix_build.Rd +++ b/man/nix_build.Rd @@ -5,21 +5,22 @@ \title{Invoke shell command \code{nix-build} from an R session} \usage{ nix_build( - exec_mode = c("blocking", "non-blocking"), - nix_file = file.path("default.nix") + nix_file = file.path("default.nix"), + exec_mode = c("blocking", "non-blocking") ) } \arguments{ -\item{exec_mode}{Either \code{"blocking"} (default) or \verb{"non-blocking}. This -will either block the R session while the \code{nix-build} shell command is -executed, or run \code{nix-build} in the background ("non-blocking").} - \item{nix_file}{File path to the \code{default.nix} file. The default is a \code{default.nix} file in the current working directory of the current R session.} + +\item{exec_mode}{Either \code{"blocking"} (default) or \verb{"non-blocking}. This +will either block the R session while the \code{nix-build} shell command is +executed, or run \code{nix-build} in the background ("non-blocking").} } \value{ -invisible +integer of the process ID (PID) of \code{nix-build} shell command +launched. } \description{ Invoke shell command \code{nix-build} from an R session