[adegenet-commits] r873 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue May 24 10:18:56 CEST 2011


Author: jombart
Date: 2011-05-24 10:18:56 +0200 (Tue, 24 May 2011)
New Revision: 873

Modified:
   pkg/R/haploGen.R
Log:
Added a "require" for graph which should solve the dependency problem.
Need to make setAs method dependent on pkg avail.


Modified: pkg/R/haploGen.R
===================================================================
--- pkg/R/haploGen.R	2011-05-17 09:27:06 UTC (rev 872)
+++ pkg/R/haploGen.R	2011-05-24 08:18:56 UTC (rev 873)
@@ -567,26 +567,28 @@
 ##########################
 ## as("haploGen", "graphNEL")
 ##########################
-if(require(graph)) setOldClass("haploGen")
-setAs("haploGen", "graphNEL", def=function(from){
-    if(!require(ape)) stop("package ape is required")
-    if(!require(graph)) stop("package graph is required")
+if(require(graph)){
+    setOldClass("haploGen")
 
-    N <- length(from$ances)
-    areNA <- is.na(from$ances)
+    setAs("haploGen", "graphNEL", def=function(from){
+        if(!require(ape)) stop("package ape is required")
+        if(!require(graph)) stop("package graph is required")
 
-    ## EXTRACT WEIGHTS (nb of mutations)
-    M <- as.matrix(dist.dna(from$seq, model="raw")*ncol(from$seq))
-    rownames(M) <- colnames(M) <- from$id
-    w <- mapply(function(i,j) {M[i, j]}, i=from$ances[!areNA], j=from$id[!areNA])
+        N <- length(from$ances)
+        areNA <- is.na(from$ances)
 
+        ## EXTRACT WEIGHTS (nb of mutations)
+        M <- as.matrix(dist.dna(from$seq, model="raw")*ncol(from$seq))
+        rownames(M) <- colnames(M) <- from$id
+        w <- mapply(function(i,j) {M[i, j]}, i=from$ances[!areNA], j=from$id[!areNA])
 
-    ## CONVERT TO GRAPH
-    res <- ftM2graphNEL(ft=cbind(from$ances[!areNA], from$id[!areNA]), W=w, edgemode = "directed", V=from$id)
-    return(res)
-})
 
+        ## CONVERT TO GRAPH
+        res <- ftM2graphNEL(ft=cbind(from$ances[!areNA], from$id[!areNA]), W=w, edgemode = "directed", V=from$id)
+        return(res)
+    })
 
+}
 
 
 
@@ -608,6 +610,7 @@
 
 
 
+
 ## #####################
 ## ## seqTrackG.haploGen
 ## #####################



More information about the adegenet-commits mailing list