<div dir="ltr"><div>Thanks everyone for helping me figure this out. Within terra::focalCpp which handles the iteration over small subsets of the data there is a test iteration that occurs which uses the data that is numbers 1-number of elements in the window (for a 3x7 window that'd be 1-21). Since the function I'm using is a bit odd in that the data refer to indices in a separate matrix (e.g. in this example a 15x15 matrix), the test data was leading to the out of bounds error when the number of elements (21) was greater than the size of that other matrix. Robert and I can figure out the rest on github so that the 2 functions play nice together.</div><div><br></div><div>Thanks,</div><div>Alex<br> </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Dec 15, 2021 at 6:24 PM Dirk Eddelbuettel <<a href="mailto:edd@debian.org">edd@debian.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
On 15 December 2021 at 12:30, Robert J. Hijmans wrote:<br>
| Dirk thanks very much for the help. And sorry, Alex, I misspoke. I meant to<br>
| say that Rcpp will coerce a R "numeric" (vector) to an<br>
| "Rcpp::IntegerVector" if you ask it to do so (and that is what happened in<br>
| the context we were discussing).<br>
<br>
Exactly. And it will be no comfort to Alex who has to chase this by hand but<br>
for those of us old enough to C/C++ time in (whole) decades, it really just<br>
smells *very much* like an old-fashioned indexing error.  Which is why<br>
valgrind was already a good idea.<br>
<br>
Minor hint:<br>
   Rcpp::stop("Something here including %d or %s or ... formatting", a, b);<br>
is a tad more Rcpp-idiomatic, and errors.  We now have Rcpp::message(...) to<br>
just do the printing (in a suppressable way). C API of R of course still holds.<br>
<br>
Dirk<br>
<br>
-- <br>
<a href="https://dirk.eddelbuettel.com" rel="noreferrer" target="_blank">https://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a><br>
</blockquote></div>