The R Project SVN R

Rev

Rev 90136 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 90136 Rev 90137
Line 1745... Line 1745...
1745
	    for (i = 0; i < n; i++) pp[i] = INTEGER(perm)[i] - 1;
1745
	    for (i = 0; i < n; i++) pp[i] = INTEGER(perm)[i] - 1;
1746
	    UNPROTECT(1);
1746
	    UNPROTECT(1);
1747
	}
1747
	}
1748
    }
1748
    }
1749
 
1749
 
-
 
1750
    /* handle the resize */
-
 
1751
    int resize = asLogical(CADDR(args));
-
 
1752
    if (resize == NA_LOGICAL) error(_("'resize' must be TRUE or FALSE"));
-
 
1753
 
-
 
1754
    /* short-circuit identity permutation (PR#19069) */
-
 
1755
    if(resize) {
-
 
1756
	bool skip = true;
-
 
1757
        for (i = 0; i < n; i++) if (pp[i] != i) {skip = false; break;}
-
 
1758
        if (skip) {UNPROTECT(1); return(a);}
-
 
1759
    }
-
 
1760
 
1750
    R_xlen_t *iip = (R_xlen_t *) R_alloc((size_t) n, sizeof(R_xlen_t));
1761
    R_xlen_t *iip = (R_xlen_t *) R_alloc((size_t) n, sizeof(R_xlen_t));
1751
    Memzero(iip, n);
1762
    Memzero(iip, n);
1752
    for (i = 0; i < n; i++)
1763
    for (i = 0; i < n; i++)
1753
	if (pp[i] >= 0 && pp[i] < n) iip[pp[i]]++;
1764
	if (pp[i] >= 0 && pp[i] < n) iip[pp[i]]++;
1754
	else error(_("value out of range in 'perm'"));
1765
	else error(_("value out of range in 'perm'"));
Line 1840... Line 1851...
1840
 
1851
 
1841
    default:
1852
    default:
1842
	UNIMPLEMENTED_TYPE("aperm", a);
1853
	UNIMPLEMENTED_TYPE("aperm", a);
1843
    }
1854
    }
1844
 
1855
 
1845
    /* handle the resize */
-
 
1846
    int resize = asLogical(CADDR(args));
-
 
1847
    if (resize == NA_LOGICAL) error(_("'resize' must be TRUE or FALSE"));
-
 
1848
 
-
 
1849
    /* and handle names(dim(.)) and the dimnames if any */
1856
    /* handle names(dim(.)) and the dimnames if any */
1850
    if (resize) {
1857
    if (resize) {
1851
	SEXP nmdm = getAttrib(dimsa, R_NamesSymbol);
1858
	SEXP nmdm = getAttrib(dimsa, R_NamesSymbol);
1852
	if(nmdm != R_NilValue) { // dimsr needs correctly permuted names()
1859
	if(nmdm != R_NilValue) { // dimsr needs correctly permuted names()
1853
	    PROTECT(nmdm);
1860
	    PROTECT(nmdm);
1854
	    SEXP nm_dr = PROTECT(allocVector(STRSXP, n));
1861
	    SEXP nm_dr = PROTECT(allocVector(STRSXP, n));