The R Project SVN R

Rev

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

Rev 88791 Rev 89147
Line 2142... Line 2142...
2142
*/
2142
*/
2143
 
2143
 
2144
/* array(data, dim, dimnames) */
2144
/* array(data, dim, dimnames) */
2145
attribute_hidden SEXP do_array(SEXP call, SEXP op, SEXP args, SEXP rho)
2145
attribute_hidden SEXP do_array(SEXP call, SEXP op, SEXP args, SEXP rho)
2146
{
2146
{
2147
    SEXP vals, ans, dims, dimnames;
-
 
2148
    R_xlen_t lendat, i, nans;
-
 
2149
 
-
 
2150
    checkArity(op, args);
2147
    checkArity(op, args);
2151
    vals = CAR(args); // = data
2148
    SEXP vals = CAR(args); // = data
2152
    /* at least NULL can get here */
2149
    /* at least NULL can get here */
2153
    switch(TYPEOF(vals)) {
2150
    switch(TYPEOF(vals)) {
2154
	case LGLSXP:
2151
	case LGLSXP:
2155
	case INTSXP:
2152
	case INTSXP:
2156
	case REALSXP:
2153
	case REALSXP:
Line 2162... Line 2159...
2162
	    break;
2159
	    break;
2163
	default:
2160
	default:
2164
	    error(_("'data' must be of a vector type, was '%s'"),
2161
	    error(_("'data' must be of a vector type, was '%s'"),
2165
		R_typeToChar(vals));
2162
		R_typeToChar(vals));
2166
    }
2163
    }
2167
    lendat = XLENGTH(vals);
2164
    SEXP ans,
2168
    dims = CADR(args);
2165
	dims     = CADR(args),
2169
    dimnames = CADDR(args);
2166
	dimnames = CADDR(args);
2170
    PROTECT(dims = coerceVector(dims, INTSXP));
2167
    PROTECT(dims = coerceVector(dims, INTSXP));
2171
    int nd = LENGTH(dims);
2168
    int nd = LENGTH(dims);
2172
    if (nd == 0) error(_("'dims' cannot be of length 0"));
2169
    if (nd == 0) error(_("'dim' cannot be of length 0"));
2173
    double d = 1.0;
2170
    double d = 1.0;
2174
    for (int j = 0; j < nd; j++) d *= INTEGER(dims)[j];
2171
    for (int j = 0; j < nd; j++) d *= INTEGER(dims)[j];
2175
#ifdef LONG_VECTOR_SUPPORT
2172
#ifdef LONG_VECTOR_SUPPORT
2176
    if (d > R_XLEN_T_MAX) error(_("too many elements specified"));
2173
    if (d > R_XLEN_T_MAX) error(_("too many elements specified"));
2177
#else
2174
#else
2178
    if (d > INT_MAX) error(_("too many elements specified"));
2175
    if (d > INT_MAX) error(_("too many elements specified"));
2179
#endif
2176
#endif
-
 
2177
    R_xlen_t lendat = XLENGTH(vals),
2180
    nans = (R_xlen_t) d;
2178
	i, nans = (R_xlen_t) d;
2181
 
2179
 
2182
    PROTECT(ans = allocVector(TYPEOF(vals), nans));
2180
    PROTECT(ans = allocVector(TYPEOF(vals), nans));
2183
    switch(TYPEOF(vals)) {
2181
    switch(TYPEOF(vals)) {
2184
    case LGLSXP:
2182
    case LGLSXP:
2185
	if (nans && lendat)
2183
	if (nans && lendat)