Skip to content

Commit

Permalink
C++ registration
Browse files Browse the repository at this point in the history
  • Loading branch information
dosorio committed May 2, 2017
1 parent ceeda9e commit 645ae31
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.travis.yml
^.*\.Rproj$
^\.Rproj\.user$
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
src/*.o
src/*.so
src/*.dll
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ importFrom(graphics,title)
importFrom(stats,embed)
importFrom(stats,optimize)
importFrom(utils,data)
useDynLib(Peptides)
useDynLib(Peptides, .registration = TRUE)
18 changes: 18 additions & 0 deletions Peptides.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageCheckArgs: --as-cran
4 changes: 4 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ absoluteCharge <- function(seq, pH = 7, pKscale = "Lehninger") {
.Call('Peptides_absoluteCharge', PACKAGE = 'Peptides', seq, pH, pKscale)
}

# Register entry points for exported C++ functions
methods::setLoadAction(function(ns) {
.Call('Peptides_RcppExport_registerCCallable', PACKAGE = 'Peptides')
})
2 changes: 1 addition & 1 deletion R/cppFunctions.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#' @useDynLib Peptides
#' @useDynLib Peptides, .registration = TRUE
#' @importFrom Rcpp sourceCpp
NULL
9 changes: 9 additions & 0 deletions inst/include/Peptides.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Generated by using Rcpp::compileAttributes() -> do not edit by hand
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#ifndef RCPP_Peptides_H_GEN_
#define RCPP_Peptides_H_GEN_

#include "Peptides_RcppExports.h"

#endif // RCPP_Peptides_H_GEN_
67 changes: 67 additions & 0 deletions inst/include/Peptides_RcppExports.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Generated by using Rcpp::compileAttributes() -> do not edit by hand
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#ifndef RCPP_Peptides_RCPPEXPORTS_H_GEN_
#define RCPP_Peptides_RCPPEXPORTS_H_GEN_

#include <Rcpp.h>

namespace Peptides {

using namespace Rcpp;

namespace {
void validateSignature(const char* sig) {
Rcpp::Function require = Rcpp::Environment::base_env()["require"];
require("Peptides", Rcpp::Named("quietly") = true);
typedef int(*Ptr_validate)(const char*);
static Ptr_validate p_validate = (Ptr_validate)
R_GetCCallable("Peptides", "Peptides_RcppExport_validate");
if (!p_validate(sig)) {
throw Rcpp::function_not_exported(
"C++ function with signature '" + std::string(sig) + "' not found in Peptides");
}
}
}

inline Rcpp::List chargeList(std::vector< std::string > seq, NumericVector pH, std::string pKscale = "Lehninger") {
typedef SEXP(*Ptr_chargeList)(SEXP,SEXP,SEXP);
static Ptr_chargeList p_chargeList = NULL;
if (p_chargeList == NULL) {
validateSignature("Rcpp::List(*chargeList)(std::vector< std::string >,NumericVector,std::string)");
p_chargeList = (Ptr_chargeList)R_GetCCallable("Peptides", "Peptides_chargeList");
}
RObject rcpp_result_gen;
{
RNGScope RCPP_rngScope_gen;
rcpp_result_gen = p_chargeList(Rcpp::wrap(seq), Rcpp::wrap(pH), Rcpp::wrap(pKscale));
}
if (rcpp_result_gen.inherits("interrupted-error"))
throw Rcpp::internal::InterruptedException();
if (rcpp_result_gen.inherits("try-error"))
throw Rcpp::exception(as<std::string>(rcpp_result_gen).c_str());
return Rcpp::as<Rcpp::List >(rcpp_result_gen);
}

inline double absoluteCharge(std::string seq, double pH = 7, std::string pKscale = "Lehninger") {
typedef SEXP(*Ptr_absoluteCharge)(SEXP,SEXP,SEXP);
static Ptr_absoluteCharge p_absoluteCharge = NULL;
if (p_absoluteCharge == NULL) {
validateSignature("double(*absoluteCharge)(std::string,double,std::string)");
p_absoluteCharge = (Ptr_absoluteCharge)R_GetCCallable("Peptides", "Peptides_absoluteCharge");
}
RObject rcpp_result_gen;
{
RNGScope RCPP_rngScope_gen;
rcpp_result_gen = p_absoluteCharge(Rcpp::wrap(seq), Rcpp::wrap(pH), Rcpp::wrap(pKscale));
}
if (rcpp_result_gen.inherits("interrupted-error"))
throw Rcpp::internal::InterruptedException();
if (rcpp_result_gen.inherits("try-error"))
throw Rcpp::exception(as<std::string>(rcpp_result_gen).c_str());
return Rcpp::as<double >(rcpp_result_gen);
}

}

#endif // RCPP_Peptides_RCPPEXPORTS_H_GEN_
3 changes: 3 additions & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.o
*.so
*.dll
71 changes: 65 additions & 6 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,92 @@
// Generated by using Rcpp::compileAttributes() -> do not edit by hand
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#include "../inst/include/Peptides.h"
#include <Rcpp.h>
#include <string>
#include <set>

using namespace Rcpp;

// chargeList
Rcpp::List chargeList(std::vector< std::string > seq, NumericVector pH, std::string pKscale);
RcppExport SEXP Peptides_chargeList(SEXP seqSEXP, SEXP pHSEXP, SEXP pKscaleSEXP) {
static SEXP Peptides_chargeList_try(SEXP seqSEXP, SEXP pHSEXP, SEXP pKscaleSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< std::vector< std::string > >::type seq(seqSEXP);
Rcpp::traits::input_parameter< NumericVector >::type pH(pHSEXP);
Rcpp::traits::input_parameter< std::string >::type pKscale(pKscaleSEXP);
rcpp_result_gen = Rcpp::wrap(chargeList(seq, pH, pKscale));
return rcpp_result_gen;
END_RCPP
END_RCPP_RETURN_ERROR
}
RcppExport SEXP Peptides_chargeList(SEXP seqSEXP, SEXP pHSEXP, SEXP pKscaleSEXP) {
SEXP rcpp_result_gen;
{
Rcpp::RNGScope rcpp_rngScope_gen;
rcpp_result_gen = PROTECT(Peptides_chargeList_try(seqSEXP, pHSEXP, pKscaleSEXP));
}
Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
if (rcpp_isInterrupt_gen) {
UNPROTECT(1);
Rf_onintr();
}
Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
if (rcpp_isError_gen) {
SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
UNPROTECT(1);
Rf_error(CHAR(rcpp_msgSEXP_gen));
}
UNPROTECT(1);
return rcpp_result_gen;
}
// absoluteCharge
double absoluteCharge(std::string seq, double pH, std::string pKscale);
RcppExport SEXP Peptides_absoluteCharge(SEXP seqSEXP, SEXP pHSEXP, SEXP pKscaleSEXP) {
static SEXP Peptides_absoluteCharge_try(SEXP seqSEXP, SEXP pHSEXP, SEXP pKscaleSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< std::string >::type seq(seqSEXP);
Rcpp::traits::input_parameter< double >::type pH(pHSEXP);
Rcpp::traits::input_parameter< std::string >::type pKscale(pKscaleSEXP);
rcpp_result_gen = Rcpp::wrap(absoluteCharge(seq, pH, pKscale));
return rcpp_result_gen;
END_RCPP
END_RCPP_RETURN_ERROR
}
RcppExport SEXP Peptides_absoluteCharge(SEXP seqSEXP, SEXP pHSEXP, SEXP pKscaleSEXP) {
SEXP rcpp_result_gen;
{
Rcpp::RNGScope rcpp_rngScope_gen;
rcpp_result_gen = PROTECT(Peptides_absoluteCharge_try(seqSEXP, pHSEXP, pKscaleSEXP));
}
Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
if (rcpp_isInterrupt_gen) {
UNPROTECT(1);
Rf_onintr();
}
Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
if (rcpp_isError_gen) {
SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
UNPROTECT(1);
Rf_error(CHAR(rcpp_msgSEXP_gen));
}
UNPROTECT(1);
return rcpp_result_gen;
}

// validate (ensure exported C++ functions exist before calling them)
static int Peptides_RcppExport_validate(const char* sig) {
static std::set<std::string> signatures;
if (signatures.empty()) {
signatures.insert("Rcpp::List(*chargeList)(std::vector< std::string >,NumericVector,std::string)");
signatures.insert("double(*absoluteCharge)(std::string,double,std::string)");
}
return signatures.find(sig) != signatures.end();
}

// registerCCallable (register entry points for exported C++ functions)
RcppExport SEXP Peptides_RcppExport_registerCCallable() {
R_RegisterCCallable("Peptides", "Peptides_chargeList", (DL_FUNC)Peptides_chargeList_try);
R_RegisterCCallable("Peptides", "Peptides_absoluteCharge", (DL_FUNC)Peptides_absoluteCharge_try);
R_RegisterCCallable("Peptides", "Peptides_RcppExport_validate", (DL_FUNC)Peptides_RcppExport_validate);
return R_NilValue;
}
2 changes: 2 additions & 0 deletions src/charge_pI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ NumericVector pHsequence(std::string seq, NumericVector pH, std::string pKscale
return charges;
}

// [[Rcpp::interfaces(r, cpp)]]
// [[Rcpp::export]]
Rcpp::List chargeList(std::vector< std::string > seq, NumericVector pH, std::string pKscale = "Lehninger"){
int size = seq.size();
Expand All @@ -288,6 +289,7 @@ Rcpp::List chargeList(std::vector< std::string > seq, NumericVector pH, std::str
return sequences;
}

// [[Rcpp::interfaces(r, cpp)]]
// [[Rcpp::export]]
double absoluteCharge(std::string seq, double pH = 7, std::string pKscale = "Lehninger"){
double charge = 0;
Expand Down
26 changes: 26 additions & 0 deletions src/init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <R.h>
#include <Rinternals.h>
#include <stdlib.h> // for NULL
#include <R_ext/Rdynload.h>

/* FIXME:
Check these declarations against the C/Fortran source code.
*/

/* .Call calls */
extern SEXP Peptides_absoluteCharge(SEXP, SEXP, SEXP);
extern SEXP Peptides_chargeList(SEXP, SEXP, SEXP);
extern SEXP Peptides_RcppExport_registerCCallable();

static const R_CallMethodDef CallEntries[] = {
{"Peptides_absoluteCharge", (DL_FUNC) &Peptides_absoluteCharge, 3},
{"Peptides_chargeList", (DL_FUNC) &Peptides_chargeList, 3},
{"Peptides_RcppExport_registerCCallable", (DL_FUNC) &Peptides_RcppExport_registerCCallable, 0},
{NULL, NULL, 0}
};

void R_init_Peptides(DllInfo *dll)
{
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
R_useDynamicSymbols(dll, FALSE);
}

0 comments on commit 645ae31

Please sign in to comment.