Add tests for R builds

This commit is contained in:
Greg Lin 2022-08-10 17:17:01 -05:00
commit 1de359f3e6
5 changed files with 505 additions and 0 deletions

View file

@ -0,0 +1,2 @@
CXX_STD=CXX11
PKG_LIBS=$(MAIN_LDFLAGS) $(LDFLAGS) $(LIBR) $(LIBS) $(LAPACK_LIBS) $(BLAS_LIBS) $(SHLIB_OPENMP_CFLAGS)

10
test/testpkg/src/add.c Normal file
View file

@ -0,0 +1,10 @@
#include <R.h>
#include <Rinternals.h>
SEXP add(SEXP a, SEXP b)
{
SEXP result = PROTECT(allocVector(REALSXP, 1));
REAL(result)[0] = asReal(a) + asReal(b);
UNPROTECT(1);
return result;
}

33
test/testpkg/src/init.c Normal file
View file

@ -0,0 +1,33 @@
#include <R.h>
#include <Rinternals.h>
#include <R_ext/Rdynload.h>
#define CALLDEF(name, n) {#name, (DL_FUNC) &name, n}
#define FDEF(name) {#name, (DL_FUNC) &F77_SUB(name), sizeof(name ## _t)/sizeof(name ## _t[0]), name ##_t}
extern SEXP add(SEXP, SEXP);
extern SEXP subtract(SEXP, SEXP);
void F77_SUB(square)(int *n, int *answer);
static R_NativePrimitiveArgType square_t[] = {
INTSXP,
INTSXP
};
static const R_CallMethodDef CallEntries[] = {
CALLDEF(add, 2),
CALLDEF(subtract, 2),
{NULL, NULL, 0}
};
static const R_FortranMethodDef fMethods[] = {
FDEF(square),
{NULL, NULL, 0}
};
void R_init_testpkg(DllInfo *dll)
{
R_registerRoutines(dll, NULL, CallEntries, fMethods, NULL);
R_useDynamicSymbols(dll, FALSE);
}

View file

@ -0,0 +1,5 @@
subroutine square(x,answer)
integer, intent(in) :: x
integer, intent(out) :: answer
answer = x * x
end

View file

@ -0,0 +1,10 @@
#include <R.h>
#include <Rinternals.h>
extern "C" SEXP subtract(SEXP a, SEXP b)
{
SEXP result = PROTECT(allocVector(REALSXP, 1));
REAL(result)[0] = asReal(a) - asReal(b);
UNPROTECT(1);
return result;
}