source_function() is the most basic way to source a C function to the R side. It sources a single C function and exports it on the R side. There is no need to include the // [[ export() ]] tag when using source_function(), since only one function will be exported.

source_function(x, includes = NULL, no_remap = TRUE, show = FALSE)

Arguments

x

[character(1)]

A block of code containing a single C function to compile.

includes

[NULL / character()]

Extra includes to add manually. By default, R.h and Rinternals.h are included. Specify more includes with their file name. For example, to include #include <Rdefines.h> you just need to specify "Rdefines.h".

no_remap

[logical(1)]

Should #define R_NO_REMAP be defined?

show

[logical(1)]

Should the output of compiling the source code with R CMD SHLIB be shown?

Value

An R function that calls the compiled C code.

Examples

code <- " SEXP fn(SEXP x) { return x; } " fn <- source_function(code) fn(1)
#> [1] 1