<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On 4 January 2016 at 21:14, Pierre Lafaye de Micheaux <span dir="ltr"><<a href="mailto:lafaye@dms.umontreal.ca" target="_blank">lafaye@dms.umontreal.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Dear all,<br>
<br>
Thanks again for your answers.<br>
<br>
For one of my project, I indeed need the special complex error functions. This is why I used the RcppFaddeeva source files in the first time.<br></blockquote><div><br></div><div>That's useful to know. In that case, I believe something could be done but I'd need some help from Dirk to make sure the package export the right things. <a href="https://github.com/baptiste/rcppfaddeeva/pull/2#issuecomment-109682706" target="_blank">https://github.com/baptiste/rcppfaddeeva/pull/2#issuecomment-109682706</a></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
This being said, it was ALSO a workaround to get access to complex numbers operations (and so that the package compile under Windows<br>
without errors).<br></blockquote><div> </div><div>This workaround is clearly suboptimal and needs to be sorted first IMHO. I'm guessing that's a magic side-effect of the Rcpp.h include in one of the files.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
I know that using .C() is now discouraged by R core group. This being said, I am a bit reluctant, at least for some projects, to use .Call().<br>
I like the idea to be able to use old FORTRAN77 codes and/or C codes written by others. Usually, using these codes is quite straightforward<br>
thanks to the .Fortran() interface. As for the C codes, it is only necessary to modify the arguments of the C function to make them pointers in<br>
order to then call it through the .C() function.<br>
<br>
My understanding, but maybe I am not good enough, is that to be able to call a C/C++ function using .Call() and/or involving Rcpp needs<br>
a lot more modifications to the original C source file.<br></blockquote><div> </div><div>If you look at RcppFaddeeva, you'll find that the original C+ library is pretty much untouched, and the c++ wrappers are quite minimal. And with Rcpp attributes, you don't even have to write R wrappers.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
I think this is bad for reproducibility. For example, if one would like to call this same C code from Matlab and if this C code is full of Rcpp, then<br>
I guess there will be some trouble. Am I right?</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
Note that I "learned" a bit of Rcpp. I am the author and maintainer of package PoweR:<br>
<a href="https://cran.r-project.org/web/packages/PoweR/index.html" rel="noreferrer" target="_blank">https://cran.r-project.org/web/packages/PoweR/index.html</a><br>
I wrote in this package the file calcpuissRcpp.cpp that contains some Rcpp features (maybe you can have a quick look to see my low? level<br>
of knowledge of Rcpp). And I agree that this is cool stuff when you want to be able to access high level<br>
R functions from C. But as said above, you loose some reproducibility (in the sense explained above) and maybe also some speed (and this is why I<br>
have two "parallel" versions in my PoweR package: calcpuiss.cpp and calcpuissRcpp.cpp).<br>
<br>
So, with all this in mind, my "request" is still the same. Namely being able to manipulate (and create) complex numbers at the (pure) C level in an R package so that it could compile properly (without errors) under Microsoft Windows. I found this workaround by copying these RcppFaddeeva source files<br>
(.cpp and .h files) in the src/ directory of my package(s) but this is not really clean. Probably I could try to remove all "unnecessary" stuff from these source<br>
files in order to keep only what is really needed to play with complex numbers at the (pure) C level, but maybe there would be something more<br>
clever to do? Like adding RcppFaddeeva to the LinkingTo/Depends/Export fields? </blockquote><div><br></div><div>I believe this step (to use some of Faddeeva's functions) needs some work in RcppFaddeeva, which I'd be happy to discuss with you and hopefully Dirk, but that's a different issue altogether.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Or creating a very simple package (by removing all special complex error<br>
functions from RcppFaddeeva) </blockquote><div><br></div><div>Sounds like a good idea to me. And if you put it on github, say, people could look at it if you get stuck. As I remember, Dirk fixed my RcppFaddeeva package faster than I was committing to it. </div><div><br></div><div>HTH,</div><div><br></div><div>baptiste</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">and call the resulting package EnableC and then add this to LinkingTo/Depends/Export fields?</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
I hope I made myself clear ...<br>
<br>
Thank you again for your time.<br>
<br>
Best regards,<br>
<br>
Pierre L.<div><div> <br></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div>
<br>
Le 03/01/2016 22:14, Dirk Eddelbuettel a écrit :<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
On 4 January 2016 at 09:50, Baptiste Auguie wrote:<br>
| Hi,<br>
|<br>
| Just to clarify: did you include files from RcppFaddeeva because you need some<br>
| of its functionality (special complex error functions), or was it only a<br>
| workaround to get access to complex numbers? In the latter case, I recommend<br>
| you try making a minimal Rcpp package to see how easy it is to interface with<br>
| C++ functions, and that way you will only have relevant header files included.<br>
<br>
+1<br>
<br>
I already responded to Pierre's initial emails in November and tried then to<br>
explain to him that that .C() is a _really bad idea at this point in time.<br>
<br>
It is two months later and nothing has changed.<br>
<br>
So here is a quick illustration of what Baptiste meant. All it takes is<br>
<br>
    library(Rcpp)    # no other depends<br>
<br>
and then (and I even got this right on first try):<br>
<br>
    R> cppFunction("Rcomplex addTwo(Rcomplex x, Rcomplex y) {return x + y; }")<br>
    R> addTwo(2+2i, 3+3i)<br>
    [1] 5+5i<br>
    R><br>
<br>
With one invocation of cppFunction() I created an ad-hoc compiled function<br>
(technically compiled as C++ but you can call this C as well) which adds two<br>
complex number -- one of Pierre's request as per the email below.  And low<br>
and behold is just does that.<br>
<br>
So yes -- maybe time to learn some Rcpp, maybe forget about .C() and simply<br>
get on with this and other other things.<br>
<br>
Dirk<br>
<br>
|<br>
| Best,<br>
|<br>
| baptiste<br>
|<br>
|<br>
|<br>
| On 4 January 2016 at 09:36, Pierre Lafaye de Micheaux <<a href="mailto:lafaye@dms.umontreal.ca" target="_blank">lafaye@dms.umontreal.ca</a>><br>
| wrote:<br>
|<br>
|     Dear all,<br>
|<br>
|     This email comes after a discussion on the R-pkg-devel mailing list:<br>
|     <a href="https://stat.ethz.ch/pipermail/r-package-devel/2016q1/000627.html" rel="noreferrer" target="_blank">https://stat.ethz.ch/pipermail/r-package-devel/2016q1/000627.html</a><br>
|<br>
|     My purpose was to be able, in two of my packages, to use complex numbers<br>
|     (create some, addition, multiplication, division, modulus, etc)<br>
|     directly in a C code that is called from R (using the .C interface).<br>
|     Note that these complex numbers might not come from R but could be created<br>
|     and used directly in my C code, that will then output (via pointers)<br>
|     real (I mean double) values back to R (via the .C interface). I could also<br>
|     send from R these complex numbers via the .C interface.<br>
|<br>
|     A very simple example of such a function called from R via the .C interface<br>
|     could be the following:<br>
|<br>
|     #include <R.h><br>
|     #include "Rmath.h"<br>
|     extern "C" {<br>
|     void Cfunc(complex double *var) {<br>
|         double _Complex z = 1.0 + 2.0 * _Complex_I;<br>
|         var[0] = z + exp(var[0]);<br>
|     return;<br>
|     }}<br>
|<br>
|     I could call this function from R as follows:<br>
|     .C(1i)<br>
|<br>
|     No problem so far when I use such a function in a package that is compiled<br>
|     under Linux. But this will not work under windows (see the discussion<br>
|     on the R-pkg-devel list). So what I did to make everything work under<br>
|     Windows also was to include in the src/ directory of my package the source<br>
|     files<br>
|     from the RcppFaddeeva package. Then I would modify the function above as<br>
|     follows:<br>
|<br>
|     #include <R.h><br>
|     #include "Rmath.h"<br>
|     #include "libraries/callFaddeeva.cpp"<br>
|     #include "libraries/Faddeeva.cpp"<br>
|     #include "libraries/RcppExports.cpp"<br>
|     extern "C" {<br>
|     void Cfunc(complex double *var) {<br>
|         cmplx z = C(1.0, 2.0);<br>
|         var[0] = z + cexp(var[0]);<br>
|     return;<br>
|     }}<br>
|<br>
|     Maybe there is a way not to include all the Faddeeva source files in my<br>
|     packages? But I do not know how to do it.<br>
|<br>
|     Best regards,<br>
|<br>
|     Pierre L.<br>
|<br>
|<br>
|<br>
|     --<br>
|     Pierre Lafaye de Micheaux<br>
|<br>
|     Adresse courrier:<br>
|     Université de Montréal<br>
|     Pavillon André-Aisenstadt<br>
|     Département de Mathématiques et Statistique<br>
|     CP 6128 Succursale Centre-ville<br>
|     Montréal Qc H3C 3J7<br>
|     CANADA<br>
|<br>
|     Adresse physique:<br>
|     Département de Mathématiques et Statistique<br>
|     Bureau 4249, Pavillon André-Aisenstadt<br>
|     2920, chemin de la Tour<br>
|     Montréal, Québec H3T 1J4<br>
|     CANADA<br>
|<br>
|     Tél.: (00-1) <a href="tel:514-343-6607" value="+15143436607" target="_blank">514-343-6607</a> / Fax: (00-1) <a href="tel:514-343-5700" value="+15143435700" target="_blank">514-343-5700</a><br>
|     <a href="mailto:lafaye@dms.umontreal.ca" target="_blank">lafaye@dms.umontreal.ca</a><br>
|     <a href="http://www.biostatisticien.eu" rel="noreferrer" target="_blank">http://www.biostatisticien.eu</a><br>
|<br>
|     _______________________________________________<br>
|     Rcpp-devel mailing list<br>
|     <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">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" rel="noreferrer" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
|<br>
|<br>
| _______________________________________________<br>
| Rcpp-devel mailing list<br>
| <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">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" rel="noreferrer" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
<br>
</blockquote>
<br>
-- <br>
Pierre Lafaye de Micheaux<br>
<br>
Adresse courrier:<br>
Université de Montréal<br>
Pavillon André-Aisenstadt<br>
Département de Mathématiques et Statistique<br>
CP 6128 Succursale Centre-ville<br>
Montréal Qc H3C 3J7<br>
CANADA<br>
<br>
Adresse physique:<br>
Département de Mathématiques et Statistique<br>
Bureau 4249, Pavillon André-Aisenstadt<br>
2920, chemin de la Tour<br>
Montréal, Québec H3T 1J4<br>
CANADA<br>
<br>
Tél.: (00-1) <a href="tel:514-343-6607" value="+15143436607" target="_blank">514-343-6607</a> / Fax: (00-1) <a href="tel:514-343-5700" value="+15143435700" target="_blank">514-343-5700</a><br>
<a href="mailto:lafaye@dms.umontreal.ca" target="_blank">lafaye@dms.umontreal.ca</a><br>
<a href="http://www.biostatisticien.eu" rel="noreferrer" target="_blank">http://www.biostatisticien.eu</a><br>
<br>
</div></div></blockquote></div><br></div></div>