View | Details | Raw Unified | Return to bug 16640 | Differences between
and this patch

Collapse All | Expand All

(-)tapply.R (-4 / +6 lines)
Lines 28-41 Link Here
28
    namelist <- lapply(INDEX, levels)#- all of them, yes !
28
    namelist <- lapply(INDEX, levels)#- all of them, yes !
29
    extent <- lengths(namelist, use.names = FALSE)
29
    extent <- lengths(namelist, use.names = FALSE)
30
    cumextent <- cumprod(extent)
30
    cumextent <- cumprod(extent)
31
    if (cumextent[nI] > .Machine$integer.max)
32
        stop("total number of levels >= 2^31")
33
    storage.mode(cumextent) <- "integer"
34
    ngroup <- cumextent[nI]
31
    ngroup <- cumextent[nI]
35
    group <- as.integer(INDEX[[1L]]) #- to contain the splitting vector
32
    group <- as.integer(INDEX[[1L]]) #- to contain the splitting vector
36
    if (nI > 1L)
33
    if (nI > 1L) {  # no integer overflow with one factor
34
        if (all(cumextent <= .Machine$integer.max)) {
35
        storage.mode(cumextent) <- "integer"
37
        for (i in 2L:nI)
36
        for (i in 2L:nI)
38
           group <- group + cumextent[i - 1L] * (as.integer(INDEX[[i]]) - 1L)
37
           group <- group + cumextent[i - 1L] * (as.integer(INDEX[[i]]) - 1L)
38
        } else if (ngroup) stop(">= 2^31 cells")
39
        else group[] <- NA # well-formed factor with 0 levels must be all NA
40
    }
39
    if (is.null(FUN)) return(group)
41
    if (is.null(FUN)) return(group)
40
    levels(group) <- as.character(seq_len(ngroup))
42
    levels(group) <- as.character(seq_len(ngroup))
41
    class(group) <- "factor"
43
    class(group) <- "factor"

Return to bug 16640