[R] .Call() function

cls59 chuck at sharpsteen.net
Thu Oct 15 07:44:09 CEST 2009




sdlywjl666 wrote:
> 
> Dear all,
>      What is the usage of the ".Call()"?
> What is the meaning of the follows:
>    
> S=.Call("RS_fractal_spectral_density_function_direct",x,as.vector(taper.),as.logical(center),as.logical(recenter),TRUE,as.integer(npad),COPY=rep(FALSE,6),CLASSES=c(rep("matrix",2),rep("logical",3),"integer"),PACKAGE="ifultools")
> 

.Call() is similar to .C() in that it calls up a compiled C function from a
dynamic library that has been loaded by R. However there is one differece--
.C() is used to pass information using standard C variable types as:

.C( 'myFunc', x = as.integer( someX ), y = as.double( someY ), PACKAGE =
'myPackage' )

Note that as.integer() and as.double() are used to ensure C receives objects
of the proper type. This would be processed by a C function with the
following definition:

void myFunc( int* x, double* y ){

  // C-level monkey business

}

.Call() is different in that it passes variables as R structures rather
basic C types. Using .Call() you don't have to wrap the arguments in
coercion functions like as.double(). The .Call() interface also expects that
the C function will return an R object:

.Call( 'myFunc', someX, someY, PACKAGE = 'myPackage' )

The C function now looks like:

#include <R.h>
#include <Rdefines.h>

SEXP myFunc( SEXP x, SEXP y ){

  // C-level monkey business with R objects

}

The other main interface is .External() which gathers all the arguments into
a single SEXP which is passed to C. More information and examples of .C(),
.Call() and .External() can be found in sections 5.2 and 5.10 of the
"Writing R Extensions" manual.


sdlywjl666 wrote:
> 
>  
> And is a function of "RS_fractal_spectral_density_function_direct"?
> Can I get the detail of "RS_fractal_spectral_density_function_direct"?
> Thanks a lot!
>  
> Best regards,
> Wang
> 
> 

That function exists as compiled code in a dynamic library loaded by the
ifultools package so there is no way to directly view it from the R console.
However, you can download the source tarball for ifultools from CRAN, untar
it and scan the C files in the source directory:

cd ifultools
cd src
grep RS_fractal_spectral_density_function_direct *

Which reveals that it lives in the file RS_fra_sdf.c


I hope this helps!

-Charlie


-----
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: http://www.nabble.com/.Call%28%29--function-tp25903072p25903325.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list