[adegenet-commits] r124 - in pkg: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jun 14 18:50:46 CEST 2008


Author: jombart
Date: 2008-06-14 18:50:46 +0200 (Sat, 14 Jun 2008)
New Revision: 124

Modified:
   pkg/R/setAs.R
   pkg/man/as-methods.Rd
Log:
Added a few setAs methods (to ktab objects).


Modified: pkg/R/setAs.R
===================================================================
--- pkg/R/setAs.R	2008-06-13 10:33:59 UTC (rev 123)
+++ pkg/R/setAs.R	2008-06-14 16:50:46 UTC (rev 124)
@@ -37,6 +37,27 @@
 
 
 
+setOldClass("ktab")
+setAs("genind", "ktab", function(from, to) {
+    if(!require(ade4)) stop("package ade4 is required")
+    res <- ktab.data.frame(df=as.data.frame(from), blocks=from at loc.nall, rownames=from at ind.names,
+                           colnames=unlist(from at all.names), tabnames=from at loc.names)
+    return(res)
+})
+
+
+
+
+setAs("genpop", "ktab", function(from, to) {
+    if(!require(ade4)) stop("package ade4 is required")
+    res <- ktab.data.frame(df=as.data.frame(from), blocks=from at loc.nall, rownames=from at pop.names,
+                           colnames=unlist(from at all.names), tabnames=from at loc.names)
+    return(res)
+})
+
+
+
+
 ##############
 # S3 versions
 ##############
@@ -67,3 +88,18 @@
 as.genpop.genind <- function(x,...){
     return(as(x,"genpop"))
 }
+
+
+
+
+as.ktab.genind <- function(x,...){
+    return(as(x,"ktab"))
+}
+
+
+
+
+as.ktab.genpop <- function(x,...){
+    return(as(x,"ktab"))
+}
+

Modified: pkg/man/as-methods.Rd
===================================================================
--- pkg/man/as-methods.Rd	2008-06-13 10:33:59 UTC (rev 123)
+++ pkg/man/as-methods.Rd	2008-06-14 16:50:46 UTC (rev 124)
@@ -6,17 +6,32 @@
 \alias{as,genind,matrix-method}
 \alias{as,genpop,matrix-method}
 \alias{as,genind,genpop-method}
+\alias{ktab-class}
+\alias{as,genind,ktab-method}
+\alias{as,genpop,ktab-method}
 \alias{coerce,genind,data.frame-method}
 \alias{coerce,genpop,data.frame-method}
 \alias{coerce,genind,matrix-method}
 \alias{coerce,genpop,matrix-method}
 \alias{coerce,genind,genpop-method}
+\alias{coerce,genind,ktab-method}
+\alias{coerce,genpop,ktab-method}
 \alias{as.data.frame.genind}
 \alias{as.data.frame.genpop}
 \alias{as.matrix.genind}
 \alias{as.matrix.genpop}
 \alias{as.genpop.genind}
+\alias{as.ktab.genind}
+\alias{as.ktab.genpop}
 \title{Converting genind/genpop objects to other classes}
+\description{
+ These S3 and S4 methods are used to coerce \linkS4class{genind} and
+ \linkS4class{genpop} objects to matrix-like objects. In most cases,
+ this is equivalent to calling the \code{@tab} slot. An exception to
+ this is the convertion to \code{\link[pkg:ade4]{ktab}} objects used in the
+ ade4 package as inputs for K-tables methods (e.g. Multiple Coinertia
+ Analysis).\cr
+}
 \section{Usage}{
 \code{as(object, Class)}
 }
@@ -27,11 +42,6 @@
     be coerced, for instance \code{"data.frame"} or \code{"matrix"}.}
 }
 }
-\description{
- These S3 and S4 methods are used to coerce \linkS4class{genind} and
- \linkS4class{genpop} objects to matrix-like objects. In most cases,
- this is equivalent to calling the \code{@tab} slot.
-}
 \section{Methods}{
   \item{coerce}{from one object class to another using
     \code{as(object,"Class")}, where the \code{object} is of the old
@@ -44,5 +54,21 @@
 data(microbov)
 x <- na.replace(microbov,method="0")
 as(x[1:3],"data.frame")
+
+## dudi functions attempt to convert their first argument
+## to a data.frame; so they can be used on genind/genpop objects.
+if(require(ade4)){
+## perform a PCA
+pca1 <- dudi.pca(x, scale=FALSE, scannf=FALSE)
+pca1
+
+x <- genind2genpop(microbov,miss="chi2")
+x <- as(x,"ktab")
+class(x)
+## perform a STATIS analysis
+statis1 <- statis(x, scannf=FALSE)
+statis1
+plot(statis1)
 }
+}
 \keyword{methods}
\ No newline at end of file



More information about the adegenet-commits mailing list