ropensci / phylocomr

Phylocom R interface
https://docs.ropensci.org/phylocomr
Other
15 stars 7 forks source link

move to using pkg sys when ready #6

Closed sckott closed 7 years ago

jeroen commented 7 years ago

The problems with sys should be fixed now as of version 1.1 on CRAN.

sckott commented 7 years ago

thanks

sckott commented 7 years ago

@jeroenooms not sure what's going wrong,

trying this, but:

install from sys branch, then

library(sys)
library(phylocomr)

tf <- tempfile()
pf <- tempfile()
cat(c("campanulaceae/lobelia/lobelia_conferta", "cyperaceae/mapania/mapania_africana", "amaryllidaceae/narcissus/narcissus_cuatrecasasii"), file = tf, sep = "\n")
cat("(((((eliea_articulata,homalanthus_populneus)malpighiales,rosa_willmottiae),((macrocentrum_neblinae,qualea_clavata),hibiscus_pohlii)malvids),(((lobelia_conferta,((millotia_depauperata,(layia_chrysanthemoides,layia_pentachaeta)layia),senecio_flanaganii)asteraceae)asterales,schwenkia_americana),tapinanthus_buntingii)),(narcissus_cuatrecasasii,mapania_africana))poales_to_asterales;", file = pf, sep = "\n")

# check they're there
file.exists(tf, pf)
readLines(tf)
readLines(pf)

args <- sprintf("-t %s -f %s", tf, pf)
path <- file.path(
  system.file("bin", .Platform$r_arch, package = "phylocomr"), "phylomatic")
out <- rawConnection(raw(0), "r+")
(res <- sys::exec_wait(path, args, std_out = out))
#> 8
rawToChar(rawConnectionValue(out))
#> "Cannot open phylogeny file\n"
jeroen commented 7 years ago

The args argument must be a character vector with args. Don't concat it into a string. Then it should work.

args <- c("-t", tf, "-f", pf)
sckott commented 7 years ago

interesting, ok. why wouldn't it also work as one string? just curious

jeroen commented 7 years ago

Actually I thought that system2 works the same way, but apparently it doesn't. The args map directly to the argument vector from the executable. So in your case the executable would be run with only one big argument, containing spaces...

jeroen commented 7 years ago

Als you might be able to simplify the code using exec_internal:


tf <- tempfile()
pf <- tempfile()
cat(c("campanulaceae/lobelia/lobelia_conferta", "cyperaceae/mapania/mapania_africana", "amaryllidaceae/narcissus/narcissus_cuatrecasasii"), file = tf, sep = "\n")
cat("(((((eliea_articulata,homalanthus_populneus)malpighiales,rosa_willmottiae),((macrocentrum_neblinae,qualea_clavata),hibiscus_pohlii)malvids),(((lobelia_conferta,((millotia_depauperata,(layia_chrysanthemoides,layia_pentachaeta)layia),senecio_flanaganii)asteraceae)asterales,schwenkia_americana),tapinanthus_buntingii)),(narcissus_cuatrecasasii,mapania_africana))poales_to_asterales;", file = pf, sep = "\n")

# check they're there
file.exists(tf, pf)
readLines(tf)
readLines(pf)

args <- c("-t", tf, "-f", pf)
path <- file.path(
  system.file("bin", .Platform$r_arch, package = "phylocomr"), "phylomatic")
out <- sys::exec_internal(path, args, error = FALSE)
rawToChar(out$stdout)
sckott commented 7 years ago

Thanks, that works.

Right, exec_internal should be easier

sckott commented 7 years ago

fixed via #7