diff --git a/R/launch.R b/R/launch.R index 241796c..4ede6d8 100644 --- a/R/launch.R +++ b/R/launch.R @@ -20,8 +20,9 @@ run <- function(dataIn) { # process and return if (inherits(captured, "error")) { + call <- conditionCall(captured) msg <- conditionMessage(captured) - cat("Error in R script", .e$path, "\n", sQuote(msg), file = stderr()) + cat("Error in R script", .e$path, "\n", sQuote(call), "\n", sQuote(msg), file = stderr()) return(invisible(F)) } .e$out$x <- if (is.null(temp)) { diff --git a/index.js b/index.js index f43b588..32125fe 100644 --- a/index.js +++ b/index.js @@ -29,9 +29,19 @@ R.prototype.call = function(_opts, _callback) { var opts = _.isFunction(_opts) ? {} : _opts; this.options.env.input = JSON.stringify([this.d, this.path, opts]); var child = child_process.spawn("Rscript", this.args, this.options); - child.stderr.on("data", callback); + var stdout = ""; + var stderr = ""; + child.stderr.on("data", function(d) { + stderr += d.toString(); + }); child.stdout.on("data", function(d) { - callback(null, JSON.parse(d)); + stdout += d; + }); + child.on("close", function(code) { + callback( + stderr ? stderr : null, + stdout ? JSON.parse(stdout) : {} + ); }); };