Skip to content

Commit

Permalink
Fix bug with warnings appearing in conversion
Browse files Browse the repository at this point in the history
system2 can't separate stdout from stderr if both are to be
catched; Two calls are necessary
  • Loading branch information
yngman committed Jul 2, 2016
1 parent 4e0de3c commit cbb7189
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions R/as_poped.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ as.poped <- function(filename, out_file=NULL) {
converter_path <- paste0(converter_path, "/pharmml2poped.exe")
command <- paste(converter_path, filename, sep=' ')

stdout <- system2(converter_path, args=c(filename), stdout=TRUE, stderr="")

err <- system2(converter_path, args=c(filename), stdout=F, stderr=T)
invisible(lapply(err, warning, call.=F))
out <- system2(converter_path, args=c(filename), stdout=T, stderr=F)

if (is.null(out_file)) {
eval(parse(text=stdout), envir=.GlobalEnv)
tryCatch(eval(parse(text=out), envir=.GlobalEnv),
error=function(e){ warning("Fatal: Could not load conversion result", call.=F) });
} else {
if (out_file == "" || tolower(out_file) == "same") {
out_file = sub("^(.*)??(\\.[[:alnum:]]+)?$", "\\1.R", filename)
}
tryCatch({
suppressWarnings(write(stdout, file=out_file))
}, error=function(e){ cat(paste0(e, " (for file '", out_file, "')")) })
suppressWarnings(write(out, file=out_file))
}, error=function(e){ warning(paste0(e, " Is file '", out_file, "' writeable?"), call.=F) })
}
invisible()
}
Expand Down

0 comments on commit cbb7189

Please sign in to comment.