Hi Romain and Dirk<span></span>,<div><br></div><div>Sorry I did not see Romain's earlier response. That is very helpful!</div><div><br></div><div>Thank you both for your prompt assistance and for developing such a useful tool.</div>
<div><br></div><div>-James</div><div><br></div><div><br><br>On Friday, August 16, 2013, Dirk Eddelbuettel  wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>

Hi James,<br>
<br>
On 16 August 2013 at 12:57, James Li wrote:<br>
| Hi Dirk,<br>
|<br>
| N could be anywhere between 3-10. <br>
<br>
Eek. 10 is a lot.<br>
<br>
| Thanks! I will definitely look into how to do those.<br>
|<br>
| Also, if <br>
|<br>
| Rcpp::NumericVector vec3 =Rcpp::NumericVector( Rcpp::Dimension(4, 5, 6));<br>
|<br>
| In this case, how do we access element vec3[1,2,3]?<br>
<br>
Well a) you cannot use [] to index, only () as the [] only allows a single<br>
index (and , is a special operator for C/C++).  Romain already sent you a<br>
first cut at something homegrown.<br>
<br>
Alternatively, if you find a matrix library dealing with N up to 10 ... you<br>
may want to consider writing glue code to access it from R via Rcpp.<br>
<br>
Cheers, Dirk<br>
<br>
| Thanks again,<br>
| James<br>
|<br>
| On Friday, August 16, 2013, Dirk Eddelbuettel wrote:<br>
|<br>
|<br>
|     Hi James,<br>
|<br>
|     On 16 August 2013 at 11:59, James Li wrote:<br>
|     | Dear Dirk and Rcpp-devel members,<br>
|     |<br>
|     | I am currently passing a multidimensional (N > 2) array (i.e.<br>
|     | array(NA, dim = rep(3,5)) ) from R via Rcpp using<br>
|<br>
|<br>
|     How big is 'N' going to be?<br>
|<br>
|     | "in C++:"<br>
|     |<br>
|     | //[[Rcpp::export]]<br>
|     | Rcpp::List check_arrayC (Rcpp::NumericVector x, Rcpp::IntegerVector<br>
|     modes){<br>
|     | //do stuff to x<br>
|     |     return Rcpp::List::create(Rcpp::_["data"] = x, Rcpp::_["modes"] =<br>
|     modes);<br>
|     | }<br>
|     |<br>
|     |<br>
|     | "in R:"<br>
|     |<br>
|     | a <- array(1:32, dim=rep(2,5))<br>
|     | b <- check_arrayC(a, dim(a))<br>
|     |<br>
|     | While I know that a multidimensional array is stored as a contiguous<br>
|     | array internally, is there currently a more natural/efficient way to<br>
|     | pass it back and forth within Rcpp?<br>
|     |<br>
|     | Also from Dirk's book, it seems that an instance of<br>
|     | Rcpp::NumericVector can be instantiated into a multidimensional array<br>
|     | via<br>
|     |<br>
|     | Rcpp::NumericVector vec3 =Rcpp::NumericVector( Rcpp::Dimension(4, 5, 6));<br>
|     |<br>
|     | In this case, how do we access element vec3[1,2,3]?<br>
|     |<br>
|     | Some background about what I am trying to do: I would like to create a<br>
|     | multidimensional array wrapper class around the base R multi-way array<br>
|     | class. I would also like to be able to pass this multidimensional<br>
|     | array via Rcpp to do all the heavy-lifting in c++. Ideally, I could<br>
|     | also convert the mda into a Boost::multi_array.<br>
|<br>
|     For a moderately-sized project (at work, not open source) I had a very good<br>
|     experience using Armadillo 'cubes' (3-d matrices) which I occassionally<br>
|     stored in 'fields' (which I though of as lists of such cubes).  I think in<br>
|     most (all?) cases I reduces data to 2-d matrices before returning that<br>
|     R. That worked great.<br>
|<br>
|     Beyond that ... you are on your own as there is very little C++ support<br>
|     already useable by Rcpp.  You'd have to write custom as<>() and wrap()<br>
|     methods (which is not hard and may well be worth it).<br>
|<br>
|     Cheers, Dirk<br>
|<br>
|     | Thanks in advance for any help.<br>
|     |<br>
|     | -James<br>
|     |<br>
|     | --<br>
|     | James Li | Ph.D. Candidate | <a href="http://jamesyili.com/" target="_blank">http://jamesyili.com/</a><br>
|     | Dept. of Statistical Science | Cornell University<br>
|     | _______________________________________________<br>
|     | Rcpp-devel mailing list<br>
|     | <a href="javascript:;" onclick="_e(event, 'cvml', 'Rcpp-devel@lists.r-forge.r-project.org')">Rcpp-devel@lists.r-forge.r-project.org</a><br>
|     | <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
|<br>
|     --<br>
|     Dirk Eddelbuettel | <a href="javascript:;" onclick="_e(event, 'cvml', 'edd@debian.org')">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a><br>

|<br>
|<br>
|<br>
| --<br>
| James Li | Ph.D. Candidate | <a href="http://jamesyili.com/" target="_blank">http://jamesyili.com/</a><br>
| Dept. of Statistical Science | Cornell University<br>
<br>
--<br>
Dirk Eddelbuettel | <a href="javascript:;" onclick="_e(event, 'cvml', 'edd@debian.org')">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a><br>
</blockquote></div><br><br>-- <br>James Li <b><font color="#3366ff">|</font></b> Ph.D. Candidate <b><font color="#3366ff">|</font></b> <a href="http://jamesyili.com/" target="_blank">http://jamesyili.com/</a><br>Dept. of Statistical Science <b><font color="#3366ff">|</font></b> Cornell University<br>