Skip to content

Commit

Permalink
Merge pull request #466 from nlmixr2/466-no-binary
Browse files Browse the repository at this point in the history
Stop requiring binary linkage
  • Loading branch information
mattfidler authored Aug 21, 2024
2 parents 9e66956 + 0ec16dd commit 21c4721
Show file tree
Hide file tree
Showing 13 changed files with 452 additions and 555 deletions.
25 changes: 22 additions & 3 deletions R/onLoad.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,29 @@
PACKAGE = "nlmixr2est")
}

# This will be saved when compiled
rxode2.api <- names(rxode2::.rxode2ptrs())

.iniRxode2Ptr <- function() {
.ptr <- rxode2::.rxode2ptrs()
.nptr <- names(.ptr)
if (length(rxode2.api) > length(.nptr)) {
stop("nlmixr2est requires a newer version of rxode2 api, cannot run nlmixr2est\ntry `install.packages(\"rxode2\")` to get a newer version of rxode2", call.=FALSE)
} else {
.nptr <- .nptr[seq_along(rxode2.api)]
if (!identical(rxode2.api, .nptr)) {
.bad <- TRUE
stop("nlmixr2est needs a different version of rxode2 api, cannot run nlmixr2est\ntry `install.packages(\"rxode2\")` to get a newer version of rxode2, or update both packages", call.=FALSE)
}
}
.Call(`_nlmixr2est_iniRxodePtrs`, .ptr,
PACKAGE = "nlmixr2est")
}

.onLoad <- function(libname, pkgname) {
backports::import(pkgname)
.iniLotriPtr()
.iniRxode2Ptr()
if (requireNamespace("generics", quietly = TRUE)) {
rxode2::.s3register("generics::tidy", "nlmixr2FitCore")
rxode2::.s3register("generics::tidy", "nlmixr2FitCoreSilent")
Expand All @@ -42,13 +62,12 @@

compiled.rxode2.md5 <- rxode2::rxMd5()


.onAttach <- function(libname, pkgname) {
## nocov start
## Setup rxode2.prefer.tbl
.iniLotriPtr()
if (compiled.rxode2.md5 != rxode2::rxMd5()) {
stop("nlmixr2 compiled against different version of rxode2, cannot run nlmixr2est\ntry `install.packages(\"nlmixr2est\", type = \"source\")` to recompile", call.=FALSE)
}
.iniRxode2Ptr()
## nlmixr2SetupMemoize()
## options(keep.source = TRUE)
## nocov end
Expand Down
4 changes: 0 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ You can install the development version of nlmixr2est from [GitHub](https://gith

``` r
# install.packages("remotes")
remotes::install_github("nlmixr2/rxode2parse")
remotes::install_github("nlmixr2/rxode2random")
remotes::install_github("nlmixr2/rxode2et")
remotes::install_github("nlmixr2/rxode2ll")
remotes::install_github("nlmixr2/rxode2")
remotes::install_github("nlmixr2/nlmixr2data")
remotes::install_github("nlmixr2/lotri")
Expand Down
2 changes: 1 addition & 1 deletion src/armahead.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <time.h>
#include <Rmath.h>
#include <RcppArmadillo.h>
#include <rxode2.h>
#include <rxode2ptr.h>


#ifndef rxDistributionNorm
Expand Down
29 changes: 13 additions & 16 deletions src/censResid.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,24 @@

#if defined(__cplusplus)

extern "C" {
typedef SEXP (*_rxode2random_rxRmvnSEXP_t)(SEXP nSSEXP, SEXP muSSEXP, SEXP sigmaSSEXP, SEXP lowerSSEXP, SEXP upperSSEXP, SEXP ncoresSSEXP, SEXP isCholSSEXP, SEXP keepNamesSSEXP, SEXP aSSEXP, SEXP tolSSEXP, SEXP nlTolSSEXP, SEXP nlMaxiterSSEXP);
extern _rxode2random_rxRmvnSEXP_t rxRmvnSEXPnlmixrEst;
}
#include <rxode2ptr.h>

static inline double truncnorm(double mean, double sd, double low, double hi){
if (R_finite(mean) && R_finite(sd)) {
NumericMatrix sigma(1,1);
sigma(0,0)=sd;
SEXP ret = rxRmvnSEXPnlmixrEst(wrap(IntegerVector::create(1)),
wrap(NumericVector::create(mean)),
wrap(sigma),
wrap(NumericVector::create(low)),
wrap(NumericVector::create(hi)),
wrap(IntegerVector::create(1)),
wrap(LogicalVector::create(false)),
wrap(LogicalVector::create(false)),
wrap(NumericVector::create(0.4)),
wrap(NumericVector::create(2.05)),
wrap(NumericVector::create(1e-10)),
wrap(IntegerVector::create(100)));
SEXP ret = _rxode2_rxRmvnSEXP_(wrap(IntegerVector::create(1)),
wrap(NumericVector::create(mean)),
wrap(sigma),
wrap(NumericVector::create(low)),
wrap(NumericVector::create(hi)),
wrap(IntegerVector::create(1)),
wrap(LogicalVector::create(false)),
wrap(LogicalVector::create(false)),
wrap(NumericVector::create(0.4)),
wrap(NumericVector::create(2.05)),
wrap(NumericVector::create(1e-10)),
wrap(IntegerVector::create(100)));
return REAL(ret)[0];
}
return NA_REAL;
Expand Down
6 changes: 3 additions & 3 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ SEXP _nlmixr2est_filterNormalLikeAndDoses(SEXP, SEXP, SEXP);

SEXP _nlmixr2est_rxode2hasLlik(void);

typedef SEXP (*_rxode2random_rxRmvnSEXP_t)(SEXP nSSEXP, SEXP muSSEXP, SEXP sigmaSSEXP, SEXP lowerSSEXP, SEXP upperSSEXP, SEXP ncoresSSEXP, SEXP isCholSSEXP, SEXP keepNamesSSEXP, SEXP aSSEXP, SEXP tolSSEXP, SEXP nlTolSSEXP, SEXP nlMaxiterSSEXP);
_rxode2random_rxRmvnSEXP_t rxRmvnSEXPnlmixrEst;
SEXP _nlmixr2est_RcppExport_registerCCallable(void);

SEXP _nlmixr2est_nlmSetup(SEXP);
Expand Down Expand Up @@ -127,7 +125,10 @@ SEXP _nlmixr2est_popedSolveIdME2(SEXP, SEXP, SEXP, SEXP, SEXP,

SEXP _nlmixr2est_iniLotriPtr(SEXP ptr);

SEXP _nlmixr2est_iniRxodePtrs(SEXP ptr);

static const R_CallMethodDef CallEntries[] = {
{"_nlmixr2est_iniRxodePtrs", (DL_FUNC) &_nlmixr2est_iniRxodePtrs, 1},
{"_nlmixr2est_iniLotriPtr", (DL_FUNC) &_nlmixr2est_iniLotriPtr, 1},
{"_nlmixr2est_uninformativeEta", (DL_FUNC) &_nlmixr2est_uninformativeEta, 1},
{"_nlmixr2est_popedSolveIdME2", (DL_FUNC) &_nlmixr2est_popedSolveIdME2, 7},
Expand Down Expand Up @@ -207,7 +208,6 @@ void R_init_nlmixr2est(DllInfo *dll)
R_registerRoutines(dll, CEntries, CallEntries, NULL, NULL);
R_useDynamicSymbols(dll, TRUE);
R_forceSymbols(dll,FALSE);
rxRmvnSEXPnlmixrEst = (_rxode2random_rxRmvnSEXP_t)R_GetCCallable("rxode2","_rxode2_rxRmvnSEXP");
}

void rxOptionsFreeFocei(void);
Expand Down
Loading

0 comments on commit 21c4721

Please sign in to comment.