Skip to content

I can´t run the example shown in the inline package

9 messages · satu, Douglas Bates, Romain Francois +1 more

#
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?
#
On Thu, Apr 8, 2010 at 11:32 AM, satu <satu2021 at live.com.ar> wrote:

            
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
[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
[1]  1  2  3  4  5  6  7  8  9 10
[1] 10
+ for (int i=0; i < *n; i++) {
+ x[i] = x[i]*x[i];
+ }"
n         x 
"integer" "numeric"
[1] "\nfor (int i=0; i < *n; i++) {\nx[i] = x[i]*x[i];\n}"
+ squarefn(n, x);
+ squarefn(n, x);
+ "
n         x 
"integer" "numeric"
[1] "\nsquarefn(n, x);\nsquarefn(n, x);\n"
+ 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.
#
Do you have the tools ? What operating system are you using ? What 
happens if you do this:

 > code <- '#include <Rdefines.h>\nSEXP f(){\n return R_NilValue ; }'
 > writeLines( code, "test.c" )
 > system( "R CMD SHLIB test.c" )
 > dyn.load( "test.so" )
 > .Call( "f" )

Romain

Le 08/04/10 20:28, satu a ?crit :

  
    
#
Dear Romain,
I am working with a PC with Windows-XP
I do have Rtools installed and running the code you propose, this is what I
get as a result:
Error in inDL(x, as.logical(local), as.logical(now), ...) : 
  unable to load shared library 'C:/Documents and Settings/L01359.BCRA/Mis
documentos/R/test.so':
  LoadLibrary failure:  No se puede encontrar el m?dulo especificado.
Error in .Call("f") : C symbol name "f" not in load table
Sergio
#
What happened to the line that contained "R CMD SHLIB" ? This is the bit 
that compiles the code.

On windows (you were asked to tell us that you are running windows, both 
through the posting guide and from my previous email) you need to 
install the same tools that one needs for building a package.

See http://cran.r-project.org/doc/manuals/R-admin.html#The-Windows-toolset

Romain

Le 09/04/10 15:11, satu a ?crit :

  
    
#
Dear Romain, you are right. Apologies, here is the complete result from your
script:
gcc -I"C:/R/R-210~1.1/include"        -O3 -Wall  -std=gnu99 -c test.c -o
test.o
gcc -shared -s -o test.dll tmp.def test.o -LC:/R/R-210~1.1/bin -lR
Error in inDL(x, as.logical(local), as.logical(now), ...) : 
  unable to load shared library 'C:/Documents and Settings/L01359.BCRA/Mis
documentos/R/test.so':
  LoadLibrary failure:  No se puede encontrar el m?dulo especificado. >
.Call( "f" ) 
Error in .Call("f") : C symbol name "f" not in load table
The system(,,,) bit seems to work, but then errors show up

Sergio
1 day later
#
On 09.04.2010 17:43, satu wrote:
On Windows it is names "test.dll".

Uwe Ligges
2 days later
#
Dear Uwe Ligges, Douglas and Romain,
You were right. After changing to test.dl it worked. After doing that I re
run the example provided in the "inline" package and worked well. It seems
to me that the  problem was that:
1) in the enviroment variables the path didn?t have the \bin folders of R
tools and 
2) they weren't at the beginning of it.
Reading more carefully the instruction now it is more clear to me.

So guys, don't know what to say but MANY THANKS to all of you.

I have another question related to the inline package, but I will write it
as a new topic 'cause it is of a different guise.

Best Regards


Sergio