<div dir="ltr">Hi,<div><br></div><div>I am trying to wrap the optim library (<a href="https://github.com/kthohr/optim">https://github.com/kthohr/optim</a>) in R via an R package using Rcpp/RcppArmadillo. Indeed, optim relies on armadillo itself. The github repository can be found here <a href="https://github.com/jchiquet/optimLibR">https://github.com/jchiquet/optimLibR</a><br><br>To do that, I put the headers of optim into inst/include/ and the cpp files into src/. Then I tried to "heuristically" pull everything together in the src/Makevars files, after my (obviously poor) understanding of the R manual pages about Makevars and from the various examples that I copied from the web (especially from the RcppMLPACK1 which, relies on the C++ library MLPACK, itself based on armadillo <a href="https://github.com/rcppmlpack/RcppMLPACK1/blob/master/src/Makevars">https://github.com/rcppmlpack/RcppMLPACK1/blob/master/src/Makevars</a>).<br><br>The package installation (including compilation of optim) successes (at least, the package can be installed). Then I tried to create two small Rcpp functions for two examples available in the original optim library, starting with the following lines<div class="gmail-m_-1175361520366330001gmail-border gmail-m_-1175361520366330001gmail-rounded-1 gmail-m_-1175361520366330001gmail-my-2" style="box-sizing:border-box;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:14px;text-decoration-style:initial;text-decoration-color:initial;border:1px solid rgb(225,228,232);border-radius:3px;margin-top:8px;margin-bottom:8px"><div class="gmail-m_-1175361520366330001gmail-blob-wrapper gmail-m_-1175361520366330001gmail-blob-wrapper-embedded gmail-m_-1175361520366330001gmail-data" style="box-sizing:border-box;overflow:auto;border-bottom-right-radius:3px;border-bottom-left-radius:3px;max-height:240px"></div></div><div class="gmail-m_-1175361520366330001gmail-highlight gmail-m_-1175361520366330001gmail-highlight-source-c++" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:14px;text-decoration-style:initial;text-decoration-color:initial;overflow:visible"><pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:11.9px;margin-top:0px;margin-bottom:0px;word-wrap:normal;padding:16px;overflow:auto;line-height:1.45;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><span class="gmail-m_-1175361520366330001gmail-pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"><span class="gmail-m_-1175361520366330001gmail-pl-c" style="box-sizing:border-box;color:rgb(106,115,125)">//</span> [[Rcpp::depends(RcppArmadillo)]]</span>
<span class="gmail-m_-1175361520366330001gmail-pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"><span class="gmail-m_-1175361520366330001gmail-pl-c" style="box-sizing:border-box;color:rgb(106,115,125)">//</span> [[Rcpp::plugins(cpp11)]]</span>
#<span class="gmail-m_-1175361520366330001gmail-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">define</span> <span class="gmail-m_-1175361520366330001gmail-pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">USE_RCPP_ARMADILLO</span>
#<span class="gmail-m_-1175361520366330001gmail-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">include</span> <span class="gmail-m_-1175361520366330001gmail-pl-s" style="box-sizing:border-box;color:rgb(3,47,98)"><span class="gmail-m_-1175361520366330001gmail-pl-pds" style="box-sizing:border-box;color:rgb(3,47,98)">"</span>optim.hpp<span class="gmail-m_-1175361520366330001gmail-pl-pds" style="box-sizing:border-box;color:rgb(3,47,98)">"</span></span></pre></div>(The #define command is an option of the optim library.)<br><br>However, when I call the corresponding R functions, I get the following Armadillo errors in R which I do not have when running them in 'pure' C++ (I am pretty sure it is not a syntax problem, the Rcpp code and the original C++ code are hopefully identical, except for the headers).<div class="gmail-m_-1175361520366330001gmail-highlight gmail-m_-1175361520366330001gmail-highlight-source-r" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:14px;text-decoration-style:initial;text-decoration-color:initial;overflow:visible"><pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:11.9px;margin-top:0px;margin-bottom:0px;word-wrap:normal;padding:16px;overflow:auto;line-height:1.45;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><span class="gmail-m_-1175361520366330001gmail-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">></span> library(<span class="gmail-m_-1175361520366330001gmail-pl-smi" style="box-sizing:border-box;color:rgb(36,41,46)">optimLibR</span>)
<span class="gmail-m_-1175361520366330001gmail-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">></span> ackley_function()
<span class="gmail-m_-1175361520366330001gmail-pl-smi" style="box-sizing:border-box;color:rgb(36,41,46)">error</span><span class="gmail-m_-1175361520366330001gmail-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">:</span> <span class="gmail-m_-1175361520366330001gmail-pl-e" style="box-sizing:border-box;color:rgb(111,66,193)">arma</span><span class="gmail-m_-1175361520366330001gmail-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">::</span><span class="gmail-m_-1175361520366330001gmail-pl-e" style="box-sizing:border-box;color:rgb(111,66,193)">memory</span><span class="gmail-m_-1175361520366330001gmail-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">::</span>acquire()<span class="gmail-m_-1175361520366330001gmail-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">:</span> <span class="gmail-m_-1175361520366330001gmail-pl-smi" style="box-sizing:border-box;color:rgb(36,41,46)">out</span> <span class="gmail-m_-1175361520366330001gmail-pl-smi" style="box-sizing:border-box;color:rgb(36,41,46)">of</span> <span class="gmail-m_-1175361520366330001gmail-pl-smi" style="box-sizing:border-box;color:rgb(36,41,46)">memory</span></pre></div><div class="gmail-m_-1175361520366330001gmail-highlight gmail-m_-1175361520366330001gmail-highlight-source-r" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:14px;text-decoration-style:initial;text-decoration-color:initial;overflow:visible"><pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:11.9px;margin-top:0px;margin-bottom:0px;word-wrap:normal;padding:16px;overflow:auto;line-height:1.45;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><span class="gmail-m_-1175361520366330001gmail-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">></span> library(<span class="gmail-m_-1175361520366330001gmail-pl-smi" style="box-sizing:border-box;color:rgb(36,41,46)">optimLibR</span>)
<span class="gmail-m_-1175361520366330001gmail-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">></span> logit_optimLib()
<span class="gmail-m_-1175361520366330001gmail-pl-smi" style="box-sizing:border-box;color:rgb(36,41,46)">error</span><span class="gmail-m_-1175361520366330001gmail-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">:</span> <span class="gmail-m_-1175361520366330001gmail-pl-e" style="box-sizing:border-box;color:rgb(111,66,193)">Mat</span><span class="gmail-m_-1175361520366330001gmail-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">::</span>init()<span class="gmail-m_-1175361520366330001gmail-pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">:</span> <span class="gmail-m_-1175361520366330001gmail-pl-smi" style="box-sizing:border-box;color:rgb(36,41,46)">requested</span> <span class="gmail-m_-1175361520366330001gmail-pl-smi" style="box-sizing:border-box;color:rgb(36,41,46)">size</span> <span class="gmail-m_-1175361520366330001gmail-pl-smi" style="box-sizing:border-box;color:rgb(36,41,46)">is</span> <span class="gmail-m_-1175361520366330001gmail-pl-smi" style="box-sizing:border-box;color:rgb(36,41,46)">not</span> <span class="gmail-m_-1175361520366330001gmail-pl-smi" style="box-sizing:border-box;color:rgb(36,41,46)">compatible</span> <span class="gmail-m_-1175361520366330001gmail-pl-smi" style="box-sizing:border-box;color:rgb(36,41,46)">with</span> <span class="gmail-m_-1175361520366330001gmail-pl-smi" style="box-sizing:border-box;color:rgb(36,41,46)">column</span> <span class="gmail-m_-1175361520366330001gmail-pl-smi" style="box-sizing:border-box;color:rgb(36,41,46)">vector</span> <span class="gmail-m_-1175361520366330001gmail-pl-smi" style="box-sizing:border-box;color:rgb(36,41,46)">layout</span></pre></div>So it seems to me that the header of armadillo are correctly defined but I am not sure that I reach the src (cpp) part of armadillo which is required at the execution.<br><br>If anyone can confirm or help pointing the origin of the error, I would be debtful...<br><br><div>Thanks for your time,<br><br>J.<p style="box-sizing:border-box;margin-top:0px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:14px;text-decoration-style:initial;text-decoration-color:initial;margin-bottom:0px">Thanks for your time</p><br></div></div></div>