Error ph_pd() form phylocomr package : Error in utils::read.table(text = out, header = TRUE, stringsAsFactors = FALSE) :no lines available in input

Viewed 20

I am trying to calculate phylogenetic diversity with ph_pd() from the phylocomr package. I have my phyllo file in nexus format, which is a consensus tree I obtained from a pool of 1000 trees downloaded from bridtree.org and then exported using

writeNexus(tree, file = "C:/R/pdtree.nex")

I also have my sample file (.csv) with three columns and tabulation as a separator that looks more or less like this

sample abundance species.code
lineage1 0 species1
lineage1 1 species2
lineage1 1 species3
lineage2 0 species1
lineage2 1 species2
lineage2 0 species3
... ... ...

The examples to use ph_pd() that can be found in the manual are:

 sfile <- system.file("examples/sample_comstruct", package = "phylocomr") 
 pfile <- system.file("examples/phylo_comstruct", package = "phylocomr")

# from data.frame
sampledf <- read.table(sfile, header = FALSE,
  stringsAsFactors = FALSE)
phylo_str <- readLines(pfile)
ph_pd(sample = sampledf, phylo = phylo_str)

# from files
sample_str <- paste0(readLines(sfile), collapse = "\n")
sfile2 <- tempfile()
cat(sample_str, file = sfile2, sep = '\n')
pfile2 <- tempfile()
phylo_str <- readLines(pfile)
cat(phylo_str, file = pfile2, sep = '\n')

ph_pd(sample = sfile2, phylo = pfile2)

An so I tried to calculate the pd for my sample like this:

sample_str <- paste0(readLines('C:/R/sample_phylo.csv'), collapse = "\n") ##el archivo con solo datos de hospedadores para COLL1
sfile2 <- tempfile()
cat(sample_str, file = sfile2, sep = '\n')
pfile2 <- tempfile()
phylo_str <- readLines('C:/R/pdtree.nex')  ##el arbol consenso que he exportado en formato nexus 
cat(phylo_str, file = pfile2, sep = '\n')

ph_pd(sample = sfile2, phylo = pfile2)

And I get the following error:

Error in utils::read.table(text = out, header = TRUE, stringsAsFactors = FALSE) : 
  no lines available in input

I have already overcome several errors while calculating this index, but this is how far I have come until getting stuck. Some colleages have suggested that the problem can come from the difference in the separation between my files and the example files (mine are tabulations), but I do not understand how to hack it or fix it.

Would be more grateful if someone could suggest a solution.

0 Answers
Related