[adegenet-commits] r697 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Oct 21 17:19:31 CEST 2010


Author: jombart
Date: 2010-10-21 17:19:30 +0200 (Thu, 21 Oct 2010)
New Revision: 697

Modified:
   pkg/R/dapc.R
Log:
Changed default behaviour when n.pca is not a vector in optim.a.score


Modified: pkg/R/dapc.R
===================================================================
--- pkg/R/dapc.R	2010-10-19 16:11:46 UTC (rev 696)
+++ pkg/R/dapc.R	2010-10-21 15:19:30 UTC (rev 697)
@@ -402,10 +402,21 @@
                          n.sim=10, n.da=length(levels(x$grp)), ...){
     ## A FEW CHECKS ##
     if(!inherits(x,"dapc")) stop("x is not a dapc object")
-    if(max(n.pca)>ncol(x$tab)) stop("too many PCA axes retained")
-    if(n.da>length(levels(x$grp))) stop("too many DA axes retained")
+    if(max(n.pca)>ncol(x$tab)) {
+        n.pca <- min(n.pca):ncol(x$tab)
+    }
+    if(n.da>length(levels(x$grp))){
+        n.da <- min(n.da):length(levels(x$grp))
+    }
     pred <- NULL
+    if(length(n.pca)==1){
+        n.pca <- 1:n.pca
+    }
+    if(length(n.da)==1){
+        n.da <- 1:da
+    }
 
+
     ## AUXILIARY FUNCTION ##
     f1 <- function(ndim){
         temp <- dapc(x$tab[,1:ndim,drop=FALSE], x$grp, n.pca=ndim, n.da=x$n.da)



More information about the adegenet-commits mailing list