-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathexecutables.R
53 lines (47 loc) · 1.24 KB
/
executables.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#' Executables
#'
#' @name executables
#' @param args a character vector of arguments to command.
#' @param intern capture output as character vector. Default: `FALSE`
#' @examples
#' ecovolve()
#' phylocom()
#' phylomatic()
#' @export
#' @rdname executables
ecovolve <- function(args = "--help", intern = FALSE) {
run("ecovolve", args, intern)
}
#' @export
#' @rdname executables
phylocom <- function(args = "help", intern = FALSE) {
run("phylocom", args, intern)
}
#' @export
#' @rdname executables
phylomatic <- function(args = "--help", intern = FALSE) {
run("phylomatic", args, intern)
}
run <- function(name, args, intern){
path <- file.path(
system.file("bin", .Platform$r_arch, package = "phylocomr"), name)
res <- sys::exec_internal(path, args, error = FALSE)
txt <- rawToChar(res$stdout)
# errors
if (!res$status %in% 0:1) {
if (res$status == 8 && name == "ecovolve") {
stop(
sprintf(
"call to 'ecovolve' failed with status %d\n only 1 taxon; > 1 required",
res$status), call. = FALSE)
} else {
stop(sprintf("call to '%s' failed with status %d\n%s", name,
res$status, txt), call. = FALSE)
}
}
if (intern) {
return(txt)
} else {
cat(txt)
}
}