[adegenet-commits] r83 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Apr 2 10:25:13 CEST 2008


Author: jombart
Date: 2008-04-02 10:25:13 +0200 (Wed, 02 Apr 2008)
New Revision: 83

Modified:
   pkg/R/classes.R
Log:
Fixed an error in genind constructor when 'pop' was not a factor (now automaticaly converted).


Modified: pkg/R/classes.R
===================================================================
--- pkg/R/classes.R	2008-03-31 10:43:44 UTC (rev 82)
+++ pkg/R/classes.R	2008-04-02 08:25:13 UTC (rev 83)
@@ -297,17 +297,19 @@
   # beware, keep levels of pop sorted in
   # there order of appearance
   if(!is.null(pop)) {
-    pop.lab <- .genlab("P",length(levels(pop)) )
-    # put pop levels in appearance order
-    pop <- as.character(pop)
-    pop <- factor(pop, levels=unique(pop))
-    temp <- pop
-    # now levels are correctly ordered
-    levels(pop) <- pop.lab
-    res at pop <- pop
-    pop.names <- as.character(levels(temp))
-    names(pop.names) <- as.character(levels(res at pop))
-    res at pop.names <- pop.names
+      # convert pop to a factor if it is not
+      if(!is.factor(pop)) {pop <- factor(pop)}
+      pop.lab <- .genlab("P",length(levels(pop)) )
+      # put pop levels in appearance order
+      pop <- as.character(pop)
+      pop <- factor(pop, levels=unique(pop))
+      temp <- pop
+      # now levels are correctly ordered
+      levels(pop) <- pop.lab
+      res at pop <- pop
+      pop.names <- as.character(levels(temp))
+      names(pop.names) <- as.character(levels(res at pop))
+      res at pop.names <- pop.names
   }
 
   if(is.null(prevcall)) {prevcall <- match.call()}



More information about the adegenet-commits mailing list