.Call
Manipulate R objects from C code

Description

The .Call and .External interfaces provide methods to call C functions, which operate directly on R objects passing R object pointers as arguments.

Usage

.Call(.NAME, ..., PACKAGE)
.External(.NAME, ..., PACKAGE)
.External2(.NAME, ..., PACKAGE)

Arguments

.NAME the name of the C function being called.
... the arguments to the C function. The number of (...) arguments are not limited for .Call and .External on most platforms.
PACKAGE the package name where the DLL containing .NAME can be found. If it is not provided, .NAME is sought in all loaded DLLs.

Details

C functions callable by .Call and .External are used to call C functions that operate directly on R objects, and whose arguments and return value are pointers to R objects (C type SEXP).
Note that on most platforms, the number of arguments that can be passed in either call type is not limited.
Value
returns the R object returned by the C function.
References
Writing R Extensions, https://cran.r-project.org/doc/manuals/R-exts.html.
See Also
.C
Examples
## Not run: 
# /* C code example
# Remove leftmost pound sign to create compilable code below.
# See "Writing R Extensions" on how to put this into a package
# or compile it on its own with "TERR CMD SHLIB code.c".
# #include <R.h>
# #include <Rinternals.h>
# 
# SEXP sequence_dotCall(SEXP pFrom, SEXP pTo, SEXP pN)
# {
#     double from = Rf_asReal(pFrom);
#     double to = Rf_asReal(pTo);
#     int n = Rf_asInteger(pN);
#     if (n <= 0)
#     {
#         Rf_error("n (%d) must be positive", n);
#     }
#     int nProtect = 0;
#     SEXP pRetval = PROTECT(Rf_allocVector(REALSXP, n)); nProtect++;
#     double *retval = REAL(pRetval);
#     retval[0] = from ;
#     for(int i = 1 ; i < n ; i++)
#     {
#         retval[i] = (double)(n-1-i)/(double)(n-1) * from + (double)(i)/(double)(n-1) * to ;
#     }
#     UNPROTECT(nProtect);
#     return pRetval;
# }
# SEXP sequence_dotExternal(SEXP args)
# {
#     return sequence_dotCall(CADR(args), CADDR(args), CADDDR(args));
# }
# If you used SHLIB then you can load it with
dyn.load(if (.Platform$OS.type == "windows") "code.dll" else "code.so")
# and use it as
.Call("sequence_dotCall", 2, 3.5, 4) # -> c(2, 2.5, 3, 3.5)
.External("sequence_dotExternal", 2, 3.5, 4) # -> c(2, 2.5, 3, 3.5)

## End(Not run)
Package base version 6.1.4-13
Package Index