I want to run some R script using the inline package (which allows to create and run inline C++ code in my humble understanding). So, after loading the required packages and copy and paste the example that runs C code (in the Reference Manual as a PDF), I have a compilation error. Any body has ever tried this inline package? -- View this message in context: http://n4.nabble.com/I-can-t-run-the-example-shown-in-the-inline-package-tp1774328p1774328.html Sent from the R help mailing list archive at Nabble.com.
Douglas Bates
2010-Apr-08 18:02 UTC
[R] I can´t run the example shown in the inline package
On Thu, Apr 8, 2010 at 11:32 AM, satu <satu2021 at live.com.ar> wrote:> I want to run some R script using the inline package (which allows to create > and run inline C++ code in my humble understanding). > So, after loading the required packages and copy and paste the example that > runs C code (in the Reference Manual as a PDF), I have a compilation error. > Any body has ever tried this inline package?Yes. Some of us use it frequently. Perhaps we could be of more help to you if you posted a log of what you tried and what the results were. Read the posting guide (URL given at the bottom of every message on this list) for suggestions on how to do so.
All is done in R 2.10.1 wiht the package "inline" version 0.3.4,,, this are the packages that I have loaded into the workspace> search()[1] ".GlobalEnv" "package:inline" "package:stats" "package:graphics" "package:grDevices" "package:datasets" "package:rcom" [8] "package:rscproxy" "package:utils" "package:methods" "Autoloads" "package:base" This is pure copy and paste from the PDF file> x <- as.numeric(1:10) > n <- as.integer(10) > x[1] 1 2 3 4 5 6 7 8 9 10> n[1] 10> sigSq <- signature(n="integer", x="numeric") > codeSq <- "+ for (int i=0; i < *n; i++) { + x[i] = x[i]*x[i]; + }"> sigSqn x "integer" "numeric"> codeSq[1] "\nfor (int i=0; i < *n; i++) {\nx[i] = x[i]*x[i];\n}"> sigQd <- signature(n="integer", x="numeric") > codeQd <- "+ squarefn(n, x); + squarefn(n, x); + "> sigQdn x "integer" "numeric"> codeQd[1] "\nsquarefn(n, x);\nsquarefn(n, x);\n"> fns <- cfunction( list(squarefn=sigSq, quadfn=sigQd),+ list(codeSq, codeQd), + convention=".C") ERROR(s) during compilation: source code errors or compiler configuration errors! Program source: 1: #include <R.h> 2: 3: 4: extern "C" { 5: void squarefn ( int * n, double * x ); 6: } 7: 8: void squarefn ( int * n, double * x ) { 9: 10: for (int i=0; i < *n; i++) { 11: x[i] = x[i]*x[i]; 12: } 13: } 14: extern "C" { 15: void quadfn ( int * n, double * x ); 16: } 17: 18: void quadfn ( int * n, double * x ) { 19: 20: squarefn(n, x); 21: squarefn(n, x); 22: 23: } Error in compileCode(f, code, language, verbose) : Compilation ERROR, function(s)/method(s) not created! Following the example shown in this PDF,,, after the fns <- cfunction( ,,, ) follows: squarefn <- fns[["squarefn"]] quadfn <- fns[["quadfn"]] squarefn(n, x)$x quadfn(n, x)$x but the compile error shows up right after the cfunction(,,,) sentence. -- View this message in context: http://n4.nabble.com/I-can-t-run-the-example-shown-in-the-inline-package-tp1774328p1778838.html Sent from the R help mailing list archive at Nabble.com.