Add tests for R builds
This commit is contained in:
parent
69b268e6f7
commit
1de359f3e6
17 changed files with 505 additions and 0 deletions
2
test/testpkg/.Rbuildignore
Normal file
2
test/testpkg/.Rbuildignore
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
^.*\.Rproj$
|
||||
^\.Rproj\.user$
|
||||
2
test/testpkg/.gitignore
vendored
Normal file
2
test/testpkg/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
.Rproj.user
|
||||
.Rhistory
|
||||
12
test/testpkg/DESCRIPTION
Normal file
12
test/testpkg/DESCRIPTION
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
Package: testpkg
|
||||
Type: Package
|
||||
Title: A Test Package
|
||||
Version: 0.1.0
|
||||
Authors@R: person("Test", "Pkg", email = "test@test", role = c("aut", "cre"))
|
||||
Description: A test package.
|
||||
License: MIT
|
||||
Depends:
|
||||
R (>= 3.1)
|
||||
SystemRequirements: C++11
|
||||
RoxygenNote: 6.1.1
|
||||
Encoding: UTF-8
|
||||
6
test/testpkg/NAMESPACE
Normal file
6
test/testpkg/NAMESPACE
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# Generated by roxygen2: do not edit by hand
|
||||
|
||||
export(add_it)
|
||||
export(square_it)
|
||||
export(subtract_it)
|
||||
useDynLib(testpkg, .registration = TRUE)
|
||||
32
test/testpkg/R/testpkg.R
Normal file
32
test/testpkg/R/testpkg.R
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#' @useDynLib testpkg, .registration = TRUE
|
||||
"_PACKAGE"
|
||||
|
||||
#' Add it together
|
||||
#'
|
||||
#' @param a Number
|
||||
#' @param b Number
|
||||
#' @return Sum of numbers
|
||||
#' @export
|
||||
add_it <- function(a, b) {
|
||||
.Call("add", a, b)
|
||||
}
|
||||
|
||||
#' Subtract it
|
||||
#'
|
||||
#' @param a Number
|
||||
#' @param b Number
|
||||
#' @return Difference of numbers
|
||||
#' @export
|
||||
subtract_it <- function(a, b) {
|
||||
.Call("subtract", a, b)
|
||||
}
|
||||
|
||||
#' Square it up
|
||||
#'
|
||||
#' @param n Integer
|
||||
#' @return Square
|
||||
#' @export
|
||||
square_it <- function(n) {
|
||||
result <- .Fortran("square", n = as.integer(n), answer = as.integer(1))
|
||||
result$answer
|
||||
}
|
||||
3
test/testpkg/README.md
Normal file
3
test/testpkg/README.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# testpkg
|
||||
|
||||
Test package with C/C++ and Fortran code, which links against libR, BLAS, LAPACK (see [Makevars](src/Makevars)).
|
||||
19
test/testpkg/man/add_it.Rd
Normal file
19
test/testpkg/man/add_it.Rd
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/testpkg.R
|
||||
\name{add_it}
|
||||
\alias{add_it}
|
||||
\title{Add it together}
|
||||
\usage{
|
||||
add_it(a, b)
|
||||
}
|
||||
\arguments{
|
||||
\item{a}{Number}
|
||||
|
||||
\item{b}{Number}
|
||||
}
|
||||
\value{
|
||||
Sum of numbers
|
||||
}
|
||||
\description{
|
||||
Add it together
|
||||
}
|
||||
17
test/testpkg/man/square_it.Rd
Normal file
17
test/testpkg/man/square_it.Rd
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/testpkg.R
|
||||
\name{square_it}
|
||||
\alias{square_it}
|
||||
\title{Square it up}
|
||||
\usage{
|
||||
square_it(n)
|
||||
}
|
||||
\arguments{
|
||||
\item{n}{Integer}
|
||||
}
|
||||
\value{
|
||||
Square
|
||||
}
|
||||
\description{
|
||||
Square it up
|
||||
}
|
||||
19
test/testpkg/man/subtract_it.Rd
Normal file
19
test/testpkg/man/subtract_it.Rd
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/testpkg.R
|
||||
\name{subtract_it}
|
||||
\alias{subtract_it}
|
||||
\title{Subtract it}
|
||||
\usage{
|
||||
subtract_it(a, b)
|
||||
}
|
||||
\arguments{
|
||||
\item{a}{Number}
|
||||
|
||||
\item{b}{Number}
|
||||
}
|
||||
\value{
|
||||
Difference of numbers
|
||||
}
|
||||
\description{
|
||||
Subtract it
|
||||
}
|
||||
14
test/testpkg/man/testpkg-package.Rd
Normal file
14
test/testpkg/man/testpkg-package.Rd
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/testpkg.R
|
||||
\docType{package}
|
||||
\name{testpkg-package}
|
||||
\alias{testpkg}
|
||||
\alias{testpkg-package}
|
||||
\title{testpkg: A Test Package}
|
||||
\description{
|
||||
A test package.
|
||||
}
|
||||
\author{
|
||||
\strong{Maintainer}: Test Pkg \email{test@test}
|
||||
|
||||
}
|
||||
2
test/testpkg/src/Makevars
Normal file
2
test/testpkg/src/Makevars
Normal 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
10
test/testpkg/src/add.c
Normal 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
33
test/testpkg/src/init.c
Normal 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);
|
||||
}
|
||||
5
test/testpkg/src/square.f
Normal file
5
test/testpkg/src/square.f
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
subroutine square(x,answer)
|
||||
integer, intent(in) :: x
|
||||
integer, intent(out) :: answer
|
||||
answer = x * x
|
||||
end
|
||||
10
test/testpkg/src/subtract.cpp
Normal file
10
test/testpkg/src/subtract.cpp
Normal 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;
|
||||
}
|
||||
19
test/testpkg/testpkg.Rproj
Normal file
19
test/testpkg/testpkg.Rproj
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
Version: 1.0
|
||||
|
||||
RestoreWorkspace: No
|
||||
SaveWorkspace: No
|
||||
AlwaysSaveHistory: No
|
||||
|
||||
EnableCodeIndexing: Yes
|
||||
UseSpacesForTab: Yes
|
||||
NumSpacesForTab: 2
|
||||
Encoding: UTF-8
|
||||
|
||||
RnwWeave: knitr
|
||||
LaTeX: pdfLaTeX
|
||||
|
||||
AutoAppendNewline: Yes
|
||||
StripTrailingWhitespace: Yes
|
||||
|
||||
BuildType: Package
|
||||
PackageRoxygenize: rd,collate,namespace
|
||||
5
test/testpkg/tests/test.R
Normal file
5
test/testpkg/tests/test.R
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
library(testpkg)
|
||||
|
||||
stopifnot(add_it(1, 2) == 3)
|
||||
stopifnot(subtract_it(1, 2) == -1)
|
||||
stopifnot(square_it(3) == 9)
|
||||
Loading…
Reference in a new issue