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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed May 14 14:52:18 CEST 2008


Author: jombart
Date: 2008-05-14 14:52:17 +0200 (Wed, 14 May 2008)
New Revision: 108

Modified:
   pkg/R/spca.R
   pkg/man/spca.Rd
Log:
Fixed handling of cn in spca. A few precisions added to the manpage.


Modified: pkg/R/spca.R
===================================================================
--- pkg/R/spca.R	2008-05-09 10:29:42 UTC (rev 107)
+++ pkg/R/spca.R	2008-05-14 12:52:17 UTC (rev 108)
@@ -23,29 +23,39 @@
   if(!inherits(obj,c("genind","genpop"))) stop("obj must be a genind or genpop object.")
   invisible(validObject(obj))
 
+  ## spatial coordinates
   if(is.null(xy) & !is.null(obj$other$xy)) xy <- obj$other$xy
   if(is.data.frame(xy)) xy <- as.matrix(xy)
-  if(ncol(xy) != 2) stop("xy does not have two columns.")
-  if(nrow(xy) != nrow(obj at tab)) stop("obj at tab and xy must have the same row numbers.")
-
+  if(!is.null(xy) & !is.matrix(xy)) stop("wrong 'xy' provided")
+  
   if(!require(ade4, quiet=TRUE)) stop("ade4 library is required.")
 
   appel <- match.call()
   
-  # connection network
+  ## connection network
   if(is.null(cn)) {
     if(is.null(xy)) stop("'xy' and 'cn' are both missing")
     resCN <- chooseCN(xy=xy, ask=ask, type=type, plot.nb=plot.nb, edit.nb=edit.nb,
                       result.type="listw", d1=d1, d2=d2, k=k, a=a, dmin=dmin)
   } else {
-      if(inherits(cn,"nb") & !inherits(cn,"listw")) { cn <- nb2listw(cn, style="W", zero.policy=TRUE) }
-      if(!inherits(cn,"listw")) stop("cn does not have a recognized class ('nb' or 'listw', package spdep)")
-      resCN <- cn
+      if(inherits(cn,"nb") & !inherits(cn,"listw")) {
+          xy <- attr(cn,"xy") # xy coords can be retrieved from cn of class nb (not from listw) 
+          cn <- nb2listw(cn, style="W", zero.policy=TRUE)
+      }
+
+      if(!inherits(cn,"listw")) {
+          stop("cn does not have a recognized class ('nb' or 'listw', package spdep)")
+      } else {
+          if(is.null(xy)) stop("listw object provided as 'cn' without providing 'xy'")
+          resCN <- cn
+      }
   }
-  
-  xy <- attr(resCN,"xy")
- 
-  # prepare data
+
+  ## check xy coordinates
+  if(ncol(xy) != 2) stop("xy does not have two columns.")
+  if(nrow(xy) != nrow(obj at tab)) stop("obj at tab and xy must have the same row numbers.")
+
+  ## prepare data
   f1 <- function(vec){
     m <- mean(vec,na.rm=TRUE)
     vec[is.na(vec)] <- m

Modified: pkg/man/spca.Rd
===================================================================
--- pkg/man/spca.Rd	2008-05-09 10:29:42 UTC (rev 107)
+++ pkg/man/spca.Rd	2008-05-14 12:52:17 UTC (rev 108)
@@ -41,7 +41,11 @@
 \arguments{
   \item{obj}{a \code{genind} or \code{genpop} object.}
   \item{xy}{a matrix or data.frame with two columns for x and y
-    coordinates. Seeked from obj\$other\$xy if it exists. Can be NULL if \code{cn} is provided.}
+    coordinates. Seeked from obj\$other\$xy if it exists when xy is not
+    provided. Can be NULL if a \code{nb} object is provided in
+    \code{cn}.\cr
+    Longitude/latitude coordinates should be converted first by a given projection (see See
+    Also section).}
   \item{cn}{a connection network of the class 'nb' (package spdep). Can
     be NULL if xy is provided. Can be easily obtained using the function
     chooseCN.}
@@ -142,7 +146,10 @@
 \seealso{\code{\link{spcaIllus}}, a set of simulated data illustrating
   the sPCA \cr
   \code{\link{global.rtest}} and \code{\link{local.rtest}} \cr
-  \code{\link{chooseCN}}, \code{\link[pkg:ade4]{multispati}}, \code{\link[pkg:ade4]{multispati.randtest}}
+  \code{\link{chooseCN}}, \code{\link[pkg:ade4]{multispati}},
+  \code{\link[pkg:ade4]{multispati.randtest}}\cr
+  \code{\link[pkg:PBSmapping]{conUL}} to convert longitude/latitude to
+  UTM coordinates.
 }
 \author{ Thibaut Jombart \email{jombart at biomserv.univ-lyon1.fr} }
 \examples{



More information about the adegenet-commits mailing list