Search code examples
rdna-sequencephylogenygenetics

Issue while drawing an haplotype network using {pegas}


I am trying to produce a haplotype network using pegas. I managed to do the basic network, but when I try to add slices of different color to each "pie" I can't seem to move forward.

I will replicate my error using the the woodmouse dataset:

data(woodmouse)
x <- woodmouse[sample(15, size = 110, replace = TRUE), ]
h <- haplotype(x)
net <- haploNet(h)
plot(net, size=attr(net, "freq"), scale.ratio = 2, cex = 0.8)

ind.hap<-with(
  stack(setNames(attr(h, "index"), rownames(h))), 
  table(hap=ind, pop=rownames(x)[values])
)

With the above code I manage to plot the network no problem, but when I try to execute the last four lines of code I get the following error:

ind.hap<-with(
  stack(setNames(attr(h, "index"), rownames(h))), 
  table(hap=ind, pop=rownames(x)[values])
)

Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘raster’ for signature ‘"integer"’

Any suggestion on what might be the problem?


Solution

  • The error message sounds like it's coming from the stack() function from the raster package rather than the base stack() function. Packages can both define functions with the same name; R will find the one from the most recently loaded package. To use the version from utils, you can prefix it with the namespace and ::. For example

    utils::stack(setNames(attr(h, "index"), rownames(h)))
    

    That should solve the problem.