Effective 3d array transposition with R/C++ (Rcpp)
If you can change the signature, to directly get cols, rows and slices count, you will not have to check for their validity.

Rcpp::NumericVector array_perm(const Rcpp::NumericVector&amp; input, 
                               std::size_t rows, std::size_t cols, std::size_t slices);


Otherwise, if you can change the error management, I think you'll get a speed boost. Exceptions handling come with a cost. Maybe return an empty vector? I don't know R , so I don't know possibilities.

You can also try to flattening your loops, here you have multiples options:

With the computations into output indexing

Rcpp::NumericVector array_perm(const Rcpp::NumericVector&amp; input, std::size_t rows, std::size_t cols, std::size_t slices) {
    // Think about the error management here...
    auto output = Rcpp::NumericVector(Rcpp::no_init(10));

    auto rc = rows * cols;
    auto size = rc * slices;
    for (std::size_t i = 0; i &lt; size; ++i) {
        output[i / rc + i % rc * slices] = input[i];
    }
    return output;
}


With the computations into intput looking

//...
    for (std::size_t i = 0; i &lt; size; ++i) output[i] = input[i/slices + i % slices * rc];
//...


Or in reverse order

//...
    while (size--) output[size] = input[size/slices + size % slices * rc];
//...


Or a mix

//...
    while (size--)  output[size / rc + size % rc * slices] = input[size];
//...


Or even a range-based for loop

//...
    std::size_t i = 0;
    for (auto e : input) {
        output[i / rc + i % rc * slices] = e;
        ++i;
    }
//...


PS: Did you tried with another contiguous storage type? (std::vector, plain old C array, ...)

PPS: I don't have R environment, so I only tested transposition algorithms with c++

Edit: 

Two other way:

//...
    for(std::size_t i = 0, j = 0; i &lt; size; ++i, j+=rc) {
        if (size &lt;= j) j -= size - 1;
        output[i] = input[j];
    }
//...
// or
//...
    for(std::size_t i = size, j = i-1; i--; j -= rc) {
        if (size &lt; j)  j += size-1;
        output[i] = input[j];
    }
//...