[adegenet-commits] r273 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Apr 1 12:27:26 CEST 2009


Author: jombart
Date: 2009-04-01 12:27:25 +0200 (Wed, 01 Apr 2009)
New Revision: 273

Modified:
   pkg/R/classes.R
Log:
fixed label handling in constructors.


Modified: pkg/R/classes.R
===================================================================
--- pkg/R/classes.R	2009-04-01 10:13:56 UTC (rev 272)
+++ pkg/R/classes.R	2009-04-01 10:27:25 UTC (rev 273)
@@ -317,10 +317,11 @@
 
     ## ind names is not type-dependent either
     ind.codes <- .genlab("", nind)
-    rownames(X) <- ind.codes
     ind.names <- .rmspaces(rownames(X))
     names(ind.names) <- ind.codes
+    rownames(X) <- ind.codes
 
+
     if(type=="codom"){
         ## loc.nall
         loc.nall <-  table(temp)[match(loc.names,names(table(temp)))]
@@ -411,29 +412,31 @@
 
     type <- match.arg(type)
     ploidy <- as.integer(ploidy)
-
-    ## labels for populations
     npop <- nrow(X)
+
+
+    ## HANDLE LABELS ##
+
+    ## loc names is not type-dependent
+    temp <- colnames(X)
+    temp <- gsub("[.].*$","",temp)
+    temp <- .rmspaces(temp)
+    loc.names <- unique(temp)
+    nloc <- length(loc.names)
+    loc.codes <- .genlab("L",nloc)
+    names(loc.names) <- loc.codes
+
+    ## pop names is not type-dependent either
+    pop.codes <- .genlab("", npop)
     pop.names <- .rmspaces(rownames(X))
-    pop.codes <- .genlab("P", npop)
     names(pop.names) <- pop.codes
+    rownames(X) <- pop.codes
 
-    ## labels for loci
-    ## and loc.nall
+    ## type-dependent stuff
     if(type=="codom"){
-        temp <- colnames(X)
-        temp <- gsub("[.].*$","",temp)
-        temp <- .rmspaces(temp)
-        # beware !!! Function 'table' gives ordred output.
-        loc.names <- unique(temp)
+        ## loc.nall
         loc.nall <-  table(temp)[match(loc.names,names(table(temp)))]
         loc.nall <- as.integer(loc.nall)
-
-        nloc <- length(loc.names)
-        loc.codes <- .genlab("L",nloc)
-
-        names(loc.names) <- loc.codes
-
         names(loc.nall) <- loc.codes
 
         ## loc.fac
@@ -453,11 +456,7 @@
         colnames(X) <- paste(loc.fac,unlist(all.codes),sep=".")
         loc.fac <- as.factor(loc.fac)
     } else { # end if type=="codom" <=> if type=="PA"
-        nloc <- ncol(X)
-        loc.codes <- .genlab("N", nloc)
         colnames(X) <- loc.codes
-        loc.names <-colnames(X)
-        names(loc.names) <- loc.codes
         loc.fac <- NULL
         all.names <- NULL
         loc.nall <- NULL



More information about the adegenet-commits mailing list