The R Project SVN R

Rev

Rev 52649 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 52649 Rev 52652
Line 1031... Line 1031...
1031
    int *pp = (int *) R_alloc(n, sizeof(int));
1031
    int *pp = (int *) R_alloc(n, sizeof(int));
1032
    perm = CADR(args);
1032
    perm = CADR(args);
1033
    if (length(perm) == 0) {
1033
    if (length(perm) == 0) {
1034
	for (i = 0; i < n; i++) pp[i] = n-1-i;
1034
	for (i = 0; i < n; i++) pp[i] = n-1-i;
1035
    } else if (isString(perm)) {
1035
    } else if (isString(perm)) {
-
 
1036
	SEXP dna = getAttrib(a, R_DimNamesSymbol);
-
 
1037
	if (isNull(dna))
-
 
1038
	    error(_("'a' does not have named dimnames"));
-
 
1039
	SEXP dnna = getAttrib(dna, R_NamesSymbol);
-
 
1040
	if (isNull(dnna))
-
 
1041
	    error(_("'a' does not have named dimnames"));
-
 
1042
	for (i = 0; i < n; i++) {
-
 
1043
	    const char *this = translateChar(STRING_ELT(perm, i));
-
 
1044
	    for (j = 0; j < n; j++)
-
 
1045
		if (streql(translateChar(STRING_ELT(dnna, j)),
-
 
1046
			   this)) {pp[i] = j; break;}
-
 
1047
	    if (j >= n)
-
 
1048
		error(_("perm[%d] does not match a dimension name"), i+1);
-
 
1049
	}
1036
    } else {
1050
    } else {
1037
	PROTECT(perm = coerceVector(perm, INTSXP));
1051
	PROTECT(perm = coerceVector(perm, INTSXP));
1038
	if (length(perm) == n) {
1052
	if (length(perm) == n) {
1039
	    for (i = 0; i < n; i++) pp[i] = INTEGER(perm)[i] - 1;
1053
	    for (i = 0; i < n; i++) pp[i] = INTEGER(perm)[i] - 1;
1040
	    UNPROTECT(1);
1054
	    UNPROTECT(1);