From 86aead6c12d22d26adbb77d417137aea04111427 Mon Sep 17 00:00:00 2001 From: "Matthew L. Fidler" Date: Tue, 26 Sep 2023 12:46:31 -0500 Subject: [PATCH] ::document() fixes --- R/RcppExports.R | 8 +-- R/err.R | 23 ++++---- man/reexports.Rd | 1 - man/rxErrTypeCombine.Rd | 2 +- man/rxRepR0_.Rd | 2 +- man/rxSetupScale.Rd | 4 +- src/expandGrid.cpp | 124 ++++++++++++++++++++-------------------- src/rxData.cpp | 26 ++++----- 8 files changed, 94 insertions(+), 96 deletions(-) diff --git a/R/RcppExports.R b/R/RcppExports.R index 7c1bd4eaf..2fe3254d1 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -39,7 +39,7 @@ etTrans <- function(inData, obj, addCmt = FALSE, dropUnits = FALSE, allTimeVar = #' @param c1 character vector of items to be expanded #' @param c2 second character vector of items to be expanded #' @param type 0 for a typical data frame, 1 for symengine sensitivity expansion -#' @return data frame (when type = 0) or symengine string (when type=1) +#' @return data frame (when type = 0) or symengine string (when type=1) #' @export #' @keywords internal rxExpandGrid_ <- function(c1, c2, type) { @@ -73,7 +73,7 @@ rxExpandSens2_ <- function(state, s1, s2) { #' #' @param state is the state to expand #' @param neta is the number of etas -#' @param pred type of prediction +#' @param pred type of prediction #' @keywords internal #' @return String of symengine expressions to evaluate to calculate df/deta #' @export @@ -83,7 +83,7 @@ rxExpandFEta_ <- function(state, neta, pred) { #' Rep R0 for foce #' -#' @param number ETA to substitute +#' @param neta ETA to substitute #' #' @return Returns a string of R code to substitute the rx_r expression in the symengine environment .s #' @@ -259,7 +259,7 @@ rxSetupIni <- function(obj, inits = NULL) { #' #' @param obj rxode2 object #' -#' @param inits A numeric vector of initial conditions. +#' @param scale A numeric vector scales #' #' @param extraArgs A list of extra args to parse for initial conditions. #' diff --git a/R/err.R b/R/err.R index c83693ee0..e432de38f 100644 --- a/R/err.R +++ b/R/err.R @@ -46,8 +46,8 @@ "f"=2:3, "dgeom"=1, "geom"=1, -# "dhyper"=3, -# "hyper"=3, + # "dhyper"=3, + # "hyper"=3, "dunif"=0:2, "unif"=0:2, "dweibull"=1:2, @@ -235,7 +235,7 @@ rxPreferredDistributionName <- function(dist) { } .rxTransformHasBounds <- function(distribution) { - (as.integer(distribution) %in% 5:14) + (as.integer(distribution) %in% 5:14) } .rxAddPropLevels <- c( @@ -337,7 +337,7 @@ rxDemoteAddErr <- function(errType) { .incompatibleErr <- function(err1, err2) { .errs <- sort(c(err1, err2)) - paste0("`", .errs[1], "` and `", .errs[2], "` are incompatible") + paste0("`", .errs[1], "` and `", .errs[2], "` are incompatible") } #' Combine error types to get the model F type #' @@ -548,12 +548,11 @@ rxDemoteAddErr <- function(errType) { #' `oldErrType` to zero assuming that there is no prior #' distribution. #' -#' @param newTransform This is the new distribution that is being +#' @param newErrType This is the new distribution that is being #' "added" to the current transformation. These assumes the inputs #' are in the preferred distribution name, as determined by #' `rxPreferredDistributionName()` #' -#' #' @return The new transformation as a factor #' #' @author Matthew Fidler @@ -601,7 +600,7 @@ rxErrTypeCombine <- function(oldErrType, newErrType) { env$.numeric <- -(expression[[2]]) return(TRUE) } else if (identical(expression[[1]], quote(`+`)) && - is.numeric(expression[[2]])) { + is.numeric(expression[[2]])) { env$.numeric <- expression[[2]] return(TRUE) } @@ -632,7 +631,7 @@ rxErrTypeCombine <- function(oldErrType, newErrType) { dexp=c("a"), #7 f=c("a", "b", "c"), #8 geom=c("a"), #9 -# hyper=c("a", "b", "c"), #10 + # hyper=c("a", "b", "c"), #10 unif=c("a", "b"), #11 weibull=c("a", "b"), #12 cauchy=c("a", "b"), @@ -1189,7 +1188,7 @@ rxErrTypeCombine <- function(oldErrType, newErrType) { setNames( c("linCmtA" = 1L, "linCmtB" = 2L, "linCmtC" = 3L - )[match.arg(linCmtSens)], + )[match.arg(linCmtSens)], NULL ), verbose )) @@ -1263,8 +1262,8 @@ rxErrTypeCombine <- function(oldErrType, newErrType) { } .mod <- eval(parse(text=paste0("quote({", .var, "=1+2\n", deparse1(expr), "})"))) .ini <- as.data.frame(eval(parse(text=paste0("lotri({\n", - paste(paste(allNames(expr[[3]]), "<- 1"), collapse="\n"), - "\n})")))) + paste(paste(allNames(expr[[3]]), "<- 1"), collapse="\n"), + "\n})")))) .env <- try(.errProcessExpression(.mod, .ini, checkMissing=FALSE), silent=TRUE) if (inherits(.env, "try-error")) return(FALSE) if (uiEnv) return(.env) @@ -1273,7 +1272,7 @@ rxErrTypeCombine <- function(oldErrType, newErrType) { #' Is Normal, Cauchy or t distribution model specification? #' #' @param expr Expression -#' +#' #' @return TRUE if this is a normal/t/cauchy model, FALSE otherwise #' @author Matthew L. Fidler #' @noRd diff --git a/man/reexports.Rd b/man/reexports.Rd index 365c14ab7..f1310e9e9 100644 --- a/man/reexports.Rd +++ b/man/reexports.Rd @@ -82,4 +82,3 @@ below to see their documentation. \item{rxode2random}{\code{\link[rxode2random:dot-cbindOme]{.cbindOme}}, \code{\link[rxode2random:dot-expandPars]{.expandPars}}, \code{\link[rxode2random:dot-vecDf]{.vecDf}}, \code{\link[rxode2random]{cvPost}}, \code{\link[rxode2random]{invWR1d}}, \code{\link[rxode2random]{phi}}, \code{\link[rxode2random]{rinvchisq}}, \code{\link[rxode2random]{rLKJ1}}, \code{\link[rxode2random]{rxGetSeed}}, \code{\link[rxode2random]{rxGetSeed}}, \code{\link[rxode2random]{rxRmvn}}, \code{\link[rxode2random]{rxSeedEng}}, \code{\link[rxode2random]{rxSetSeed}}, \code{\link[rxode2random]{rxSetSeed}}, \code{\link[rxode2random]{rxSetSeed}}, \code{\link[rxode2random:rxWithSeed]{rxWithPreserveSeed}}, \code{\link[rxode2random]{rxWithSeed}}, \code{\link[rxode2random]{rxWithSeed}}} }} -\value{ Inherited from parent routine } diff --git a/man/rxErrTypeCombine.Rd b/man/rxErrTypeCombine.Rd index c2b5f3484..1b6ed455b 100644 --- a/man/rxErrTypeCombine.Rd +++ b/man/rxErrTypeCombine.Rd @@ -15,7 +15,7 @@ swaps \code{oldErrType} and \code{addTransform} and assigns \code{oldErrType} to zero assuming that there is no prior distribution.} -\item{newTransform}{This is the new distribution that is being +\item{newErrType}{This is the new distribution that is being "added" to the current transformation. These assumes the inputs are in the preferred distribution name, as determined by \code{rxPreferredDistributionName()}} diff --git a/man/rxRepR0_.Rd b/man/rxRepR0_.Rd index c0b7b8ecf..6175734e6 100644 --- a/man/rxRepR0_.Rd +++ b/man/rxRepR0_.Rd @@ -7,7 +7,7 @@ rxRepR0_(neta) } \arguments{ -\item{number}{ETA to substitute} +\item{neta}{ETA to substitute} } \value{ Returns a string of R code to substitute the rx_r expression in the symengine environment .s diff --git a/man/rxSetupScale.Rd b/man/rxSetupScale.Rd index 005282f1e..e3cc32a56 100644 --- a/man/rxSetupScale.Rd +++ b/man/rxSetupScale.Rd @@ -9,9 +9,9 @@ rxSetupScale(obj, scale = NULL, extraArgs = NULL) \arguments{ \item{obj}{rxode2 object} -\item{extraArgs}{A list of extra args to parse for initial conditions.} +\item{scale}{A numeric vector scales} -\item{inits}{A numeric vector of initial conditions.} +\item{extraArgs}{A list of extra args to parse for initial conditions.} } \value{ setup scale for changing compartment values diff --git a/src/expandGrid.cpp b/src/expandGrid.cpp index aa6fa8b88..73a738673 100644 --- a/src/expandGrid.cpp +++ b/src/expandGrid.cpp @@ -22,7 +22,7 @@ std::string symengineRes(std::string val); //' @param c1 character vector of items to be expanded //' @param c2 second character vector of items to be expanded //' @param type 0 for a typical data frame, 1 for symengine sensitivity expansion -//' @return data frame (when type = 0) or symengine string (when type=1) +//' @return data frame (when type = 0) or symengine string (when type=1) //' @export //' @keywords internal //[[Rcpp::export]] @@ -39,10 +39,10 @@ List rxExpandGrid_(RObject &c1, RObject &c2, RObject &type){ int iType = as(type); if (iType == 0){ for (int i = lenF; i--;){ - i1 = i % len1; - i2 = std::floor(i / len1); - out1[i] = in1[i1]; - out2[i] = in2[i2]; + i1 = i % len1; + i2 = std::floor(i / len1); + out1[i] = in1[i1]; + out2[i] = in2[i2]; } List out(2); out[0] = out1; @@ -56,17 +56,17 @@ List rxExpandGrid_(RObject &c1, RObject &c2, RObject &type){ CharacterVector out4(lenF); CharacterVector out5(lenF); for (int i = lenF; i--;){ - i1 = i % len1; - i2 = std::floor(i / len1); - std::string s1 = as(in1[i1]); - std::string s2 = as(in2[i2]); - out1[i] = s1; - out2[i] = s2; - out3[i] = "df(" + s1 + ")/dy(" + s2 + ")"; - std::string sDf = "rx__df_" + s1 + "_dy_" + s2 + "__"; - out4[i] = sDf; - out5[i] = "assign(\"" + sDf + "\",with(model,D(rx__d_dt_" + - s1 + "__, \"" + symengineRes(s2) + "\")), envir=model)"; + i1 = i % len1; + i2 = std::floor(i / len1); + std::string s1 = as(in1[i1]); + std::string s2 = as(in2[i2]); + out1[i] = s1; + out2[i] = s2; + out3[i] = "df(" + s1 + ")/dy(" + s2 + ")"; + std::string sDf = "rx__df_" + s1 + "_dy_" + s2 + "__"; + out4[i] = sDf; + out5[i] = "assign(\"" + sDf + "\",with(model,D(rx__d_dt_" + + s1 + "__, \"" + symengineRes(s2) + "\")), envir=model)"; } List out(5); out[0] = out1; @@ -131,7 +131,7 @@ List rxExpandSens_(CharacterVector state, CharacterVector calcSens){ std::string curState2=as(state[j]); // sprintf("df(%s)/dy(%s)*rx__sens_%s_BY_%s__", s1, rxToSymPy(s2), s2, rxToSymPy(sns)) curLine += "rx__df_"+curState+"_dy_"+curState2+ - "__*rx__sens_"+curState2+"_BY_"+curSens+"__+"; + "__*rx__sens_"+curState2+"_BY_"+curSens+"__+"; } curLine += "rx__df_"+curState+ "_dy_"+curSens+"__),envir=model)"; line[i] = curLine; @@ -166,8 +166,8 @@ List rxExpandSens_(CharacterVector state, CharacterVector calcSens){ out[13] = FS; out[14] = FR; out.attr("names") = CharacterVector::create("ddt","ddtS","line","s0", "s0D","s0r", "ddS2", - "rateS","rateR", "durS","durR","lagS", "lagR", - "fS","fR"); + "rateS","rateR", "durS","durR","lagS", "lagR", + "fS","fR"); out.attr("class") = "data.frame"; out.attr("row.names") = IntegerVector::create(NA_INTEGER, -lenF); return out; @@ -217,9 +217,9 @@ List rxExpandSens2_(CharacterVector state, CharacterVector s1, CharacterVector s for (int j = len1; j--;){ std::string s2 = as(state[j]); curLine += "+D("+v1+",\""+symengineRes(s2)+"\")*rx__sens_"+s2+"_BY_"+cS1+ - "__+rx__sens_"+s2+"_BY_"+cS1+"_BY_"+cS2+ - "__*rx__df_"+ - cS + "_dy_"+s2+"__"; + "__+rx__sens_"+s2+"_BY_"+cS1+"_BY_"+cS2+ + "__*rx__df_"+ + cS + "_dy_"+s2+"__"; } curLine += "),envir=model)"; line[i] = curLine; @@ -240,14 +240,14 @@ List rxExpandSens2_(CharacterVector state, CharacterVector s1, CharacterVector s out.attr("names") = CharacterVector::create("ddt","ddtS","ddS2","line","s0r","s0D","s0"); out.attr("class") = "data.frame"; out.attr("row.names") = IntegerVector::create(NA_INTEGER, -lenF); - return out; + return out; } //' Expand d(f)/d(eta) //' //' @param state is the state to expand //' @param neta is the number of etas -//' @param pred type of prediction +//' @param pred type of prediction //' @keywords internal //' @return String of symengine expressions to evaluate to calculate df/deta //' @export @@ -264,34 +264,34 @@ List rxExpandFEta_(CharacterVector state, int neta, int pred){ switch(pred){ case 2: feta = "rx__sens_rx_pred__BY_ETA_" + - etaN + "___"; + etaN + "___"; calc = "assign(\"" + feta + "\",with(.s,-D(rx_pred_, ETA_" + - etaN + "_)"; + etaN + "_)"; for (int j = nstate; j--;){ - calc += "-rx__sens_" + as(state[j]) + "_BY_ETA_" + etaN + - "___*D(rx_pred_,\""+ symengineRes(as(state[j])) + "\")"; + calc += "-rx__sens_" + as(state[j]) + "_BY_ETA_" + etaN + + "___*D(rx_pred_,\""+ symengineRes(as(state[j])) + "\")"; } calc += "), envir=.s)"; break; case 1: feta = "rx__sens_rx_pred__BY_ETA_" + - etaN + "___"; + etaN + "___"; calc = "assign(\"" + feta + "\",with(.s,D(rx_pred_, ETA_" + - etaN + "_)"; + etaN + "_)"; for (int j = nstate; j--;){ - calc += "+rx__sens_" + as(state[j]) + "_BY_ETA_" + etaN + - "___*D(rx_pred_,"+ symengineRes(as(state[j])) + ")"; + calc += "+rx__sens_" + as(state[j]) + "_BY_ETA_" + etaN + + "___*D(rx_pred_,"+ symengineRes(as(state[j])) + ")"; } calc += "), envir=.s)"; break; case 0: feta = "rx__sens_rx_r__BY_ETA_" + - etaN + "___"; + etaN + "___"; calc = "assign(\"" + feta + "\",with(.s,D(rx_r_,ETA_" + - etaN + "_)"; + etaN + "_)"; for (int j = nstate; j--;){ - calc += "+rx__sens_" + as(state[j]) + "_BY_ETA_" + etaN + - "___*D(rx_r_,"+ symengineRes(as(state[j])) + ")"; + calc += "+rx__sens_" + as(state[j]) + "_BY_ETA_" + etaN + + "___*D(rx_r_,"+ symengineRes(as(state[j])) + ")"; } calc += "), envir=.s)"; break; @@ -310,7 +310,7 @@ List rxExpandFEta_(CharacterVector state, int neta, int pred){ //' Rep R0 for foce //' -//' @param number ETA to substitute +//' @param neta ETA to substitute //' //' @return Returns a string of R code to substitute the rx_r expression in the symengine environment .s //' @@ -332,15 +332,15 @@ List rxModelVars_(const RObject &obj); // Expands nesting for theta/eta; // // @param thetaNest -// +// // @noRd void rxExpandNestingRep(CharacterVector &thetaNest, - CharacterVector &thetaNestTran, - CharacterVector &thetaNestFull, - int &thCnt, int &curtheta, - List &aboveVars, NumericVector& above, - std::string &retS, - List &data, std::string thetaVar = "THETA[") { + CharacterVector &thetaNestTran, + CharacterVector &thetaNestFull, + int &thCnt, int &curtheta, + List &aboveVars, NumericVector& above, + std::string &retS, + List &data, std::string thetaVar = "THETA[") { std::string theta; int lastTheta; int firstTheta = curtheta; @@ -356,14 +356,14 @@ void rxExpandNestingRep(CharacterVector &thetaNest, std::string curPar = as(nestVars[i]); retS += curPar + "="; for (int k = 0; k < nnest; ++k) { - theta = thetaVar + std::to_string(lastTheta+i+k*nnest+firstTheta) + "]"; - retS += "(" + curNest + "==" + std::to_string(k+1)+")*" + theta; - thetaNestTran[thCnt] = curPar + "(" + curNest + "==" + - as(curNestLvl[k])+")"; - thetaNestFull[thCnt] = theta; - curtheta++; thCnt++; - if (k != nnest-1) retS += "+"; - else retS += ";\n"; + theta = thetaVar + std::to_string(lastTheta+i+k*nnest+firstTheta) + "]"; + retS += "(" + curNest + "==" + std::to_string(k+1)+")*" + theta; + thetaNestTran[thCnt] = curPar + "(" + curNest + "==" + + as(curNestLvl[k])+")"; + thetaNestFull[thCnt] = theta; + curtheta++; thCnt++; + if (k != nnest-1) retS += "+"; + else retS += ";\n"; } } } @@ -373,7 +373,7 @@ void rxExpandNestingRep(CharacterVector &thetaNest, //[[Rcpp::export]] List rxExpandNesting(const RObject& obj, List& nestingInfo, - bool compile=false){ + bool compile=false){ std::string retS=""; List mv = rxModelVars_(obj); IntegerVector flags = as(mv["flags"]); @@ -414,23 +414,23 @@ List rxExpandNesting(const RObject& obj, List& nestingInfo, if (thetaNest.size() > 0) { rxExpandNestingRep(thetaNest, thetaNestTran, thetaNestFull, - thCnt, curtheta, aboveVars, above, retS, data, - "THETA["); + thCnt, curtheta, aboveVars, above, retS, data, + "THETA["); } else if (etaNest.size() == 0) { // const RObject& obj, List& nestingInfo, - // bool compile=false + // bool compile=false CharacterVector blank; blank.attr("names") = CharacterVector::create(); return List::create(_["mod"] = obj, - _["theta"] = blank, - _["eta"] = blank); + _["theta"] = blank, + _["eta"] = blank); } - + int etCnt = 0; rxExpandNestingRep(etaNest, etaNestTran, etaNestFull, - etCnt, cureta, - belowVars, below, retS, data, - "ETA["); + etCnt, cureta, + belowVars, below, retS, data, + "ETA["); CharacterVector mod = mv["model"]; List ret(3); retS += as(mod[0]); diff --git a/src/rxData.cpp b/src/rxData.cpp index 479f16a57..976c49bd8 100644 --- a/src/rxData.cpp +++ b/src/rxData.cpp @@ -1224,7 +1224,7 @@ NumericVector rxSetupIni(const RObject &obj, //' //' @param obj rxode2 object //' -//' @param inits A numeric vector of initial conditions. +//' @param scale A numeric vector scales //' //' @param extraArgs A list of extra args to parse for initial conditions. //' @@ -1755,12 +1755,12 @@ void rxSimOmega(bool &simOmega, defaultType = 3; } RObject ol = _rxode2_cvPost_(as(NumericVector::create(dfSub)), - as(omegaMC), - as(IntegerVector::create(1)), - as(LogicalVector::create(false)), - as(LogicalVector::create(false)), - as(IntegerVector::create(defaultType)), - as(IntegerVector::create(omegaXform))); + as(omegaMC), + as(IntegerVector::create(1)), + as(LogicalVector::create(false)), + as(LogicalVector::create(false)), + as(IntegerVector::create(defaultType)), + as(IntegerVector::create(omegaXform))); if (TYPEOF(ol) == VECSXP) { omegaList = ol; } else { @@ -1768,12 +1768,12 @@ void rxSimOmega(bool &simOmega, } } else { RObject ol = _rxode2_cvPost_(as(NumericVector::create(dfSub)), - as(omegaMC), - as(IntegerVector::create(nStud)), - as(LogicalVector::create(true)), - as(LogicalVector::create(false)), - as(IntegerVector::create(1)), - as(IntegerVector::create(1))); + as(omegaMC), + as(IntegerVector::create(nStud)), + as(LogicalVector::create(true)), + as(LogicalVector::create(false)), + as(IntegerVector::create(1)), + as(IntegerVector::create(1))); if (TYPEOF(ol) == VECSXP) { omegaList = ol; } else {