From 1a130c3a7a53c35f1a0dc3509f7632203e8d980d Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Thu, 2 Nov 2017 17:44:10 -0400 Subject: [PATCH] updated matlabr --- DESCRIPTION | 2 +- R/matlab_script.R | 16 +++++++++++++--- man/get_matlab.Rd | 5 ++++- man/run_matlab_script.Rd | 5 ++++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d544ffe..ba460df 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: matlabr Type: Package Title: An Interface for MATLAB using System Calls -Version: 1.4.3 +Version: 1.5.0 Date: 2017-10-10 Authors@R: person(given = "John", family = "Muschelli", diff --git a/R/matlab_script.R b/R/matlab_script.R index 3e8a960..2e0a61c 100644 --- a/R/matlab_script.R +++ b/R/matlab_script.R @@ -8,6 +8,8 @@ #' @param desktop Should desktop be active for MATLAB? #' @param splash Should splash be active for MATLAB? #' @param display Should display be active for MATLAB? +#' @param wait Should R wait for the command to finish. Both +#' passed to \code{\link{system}} and adds the \code{-wait} flag. #' @export #' @return Character of command for matlab #' @examples @@ -18,7 +20,8 @@ get_matlab = function( try_defaults = TRUE, desktop = FALSE, splash = FALSE, - display = FALSE){ + display = FALSE, + wait = TRUE){ # find.matlab <- system("which matlab", ignore.stdout=TRUE) mat = paste0( "matlab", @@ -35,8 +38,13 @@ get_matlab = function( desktop = myfunc(desktop, "desktop") splash = myfunc(splash, "splash") display = myfunc(display, "display") + wait = ifelse( + .Platform$OS.type %in% "windows", + ifelse(wait, "-wait", ""), + "") matcmd <- paste0(mat, " ", + wait, " ", desktop, " ", splash, " ", display, " -r ") @@ -110,12 +118,14 @@ run_matlab_script = function( desktop = FALSE, splash = FALSE, display = FALSE, + wait = TRUE, ...){ stopifnot(file.exists(fname)) matcmd = get_matlab( desktop = desktop, splash = splash, - display = display) + display = display, + wait = wait) cmd = paste0(' "', "try, run('", fname, "'); ", "catch err, disp(err.message); ", "exit(1); end; exit(0);", '"') @@ -124,7 +134,7 @@ run_matlab_script = function( message("Command run is:") message(cmd) } - x <- system(cmd, ...) + x <- system(cmd, wait = wait, ...) return(x) } diff --git a/man/get_matlab.Rd b/man/get_matlab.Rd index a02cdcc..89cbac8 100644 --- a/man/get_matlab.Rd +++ b/man/get_matlab.Rd @@ -5,7 +5,7 @@ \title{Find matlab path} \usage{ get_matlab(try_defaults = TRUE, desktop = FALSE, splash = FALSE, - display = FALSE) + display = FALSE, wait = TRUE) } \arguments{ \item{try_defaults}{(logical) If \code{matlab} is not found from @@ -17,6 +17,9 @@ default PATHs for Linux and OS X.} \item{splash}{Should splash be active for MATLAB?} \item{display}{Should display be active for MATLAB?} + +\item{wait}{Should R wait for the command to finish. Both +passed to \code{\link{system}} and adds the \code{-wait} flag.} } \value{ Character of command for matlab diff --git a/man/run_matlab_script.Rd b/man/run_matlab_script.Rd index 3b16d12..1a5392c 100644 --- a/man/run_matlab_script.Rd +++ b/man/run_matlab_script.Rd @@ -5,7 +5,7 @@ \title{Run matlab script} \usage{ run_matlab_script(fname, verbose = TRUE, desktop = FALSE, splash = FALSE, - display = FALSE, ...) + display = FALSE, wait = TRUE, ...) } \arguments{ \item{fname}{Filename of matlab script (.m file)} @@ -18,6 +18,9 @@ run_matlab_script(fname, verbose = TRUE, desktop = FALSE, splash = FALSE, \item{display}{Should display be active for MATLAB?} +\item{wait}{Should R wait for the command to finish. Both +passed to \code{\link{system}} and adds the \code{-wait} flag.} + \item{...}{Options passed to \code{\link{system}}} } \value{