Skip to content

Commit

Permalink
Merge pull request #2 from zkamvar/master
Browse files Browse the repository at this point in the history
Fix rhs/data issue in amova
  • Loading branch information
emmanuelparadis committed Apr 30, 2015
2 parents 399894d + f829723 commit 45bd3ff
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions pegas/R/amova.R
Expand Up @@ -15,15 +15,20 @@ amova <- function(formula, data = NULL, nperm = 1000, is.squared = FALSE)
## keep the highest level first:
if (length(rhs) > 1) gr.nms <- unlist(strsplit(gr.nms, "/"))

if (any(sapply(gr.nms, function(x) ! is.factor(eval(parse(text = x)))))) {
## <FIXME>
## a warning instead of an error so that StAMMP on CRAN does not
## fail. I wrote to Pemberton but got no reply (2014-08-21)
warning("elements in the rhs of the formula are not all factors")
## stop("all elements in the rhs of the formula must be factors")
## </FIXME>
data.env <- if (is.null(data)) .GlobalEnv
else as.environment(data)

if (any(sapply(gr.nms, function(x) ! is.factor(get(x, envir = data.env))))) {
## <FIXME>
## a warning instead of an error so that StAMMP on CRAN does not
## fail. I wrote to Pemberton but got no reply (2014-08-21)
warning("elements in the rhs of the formula are not all factors")
## stop("all elements in the rhs of the formula must be factors")
## </FIXME>
}


gr <- as.data.frame(sapply(gr.nms, get, envir = data.env))

y <- get(y.nms)
if (any(is.na(y)))
warning("at least one missing value in the distance object.")
Expand All @@ -33,9 +38,7 @@ amova <- function(formula, data = NULL, nperm = 1000, is.squared = FALSE)
stop("the lhs of the formula must be either a matrix or an object of class 'dist'.")
n <- dim(y)[1] # number of individuals

gr <-
if (is.null(data)) as.data.frame(sapply(gr.nms, get, envir = .GlobalEnv))
else data[gr.nms]

Nlv <- length(gr) # number of levels

### 5 local functions
Expand Down

0 comments on commit 45bd3ff

Please sign in to comment.