/
RcppExports.R
614 lines (555 loc) · 17.7 KB
/
RcppExports.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
#' Event translation for rxode2
#'
#' @param inData Data frame to translate
#'
#' @param obj Model to translate data
#'
#' @param addCmt Add compartment to data frame (default `FALSE`).
#'
#' @param dropUnits Boolean to drop the units (default `FALSE`).
#'
#' @param allTimeVar Treat all covariates as if they were time-varying
#'
#' @param keepDosingOnly keep the individuals who only have dosing records and any
#' trailing dosing records after the last observation.
#'
#' @param combineDvid is a boolean indicating if rxode2 will use `DVID` on observation
#' records to change the `cmt` value; Useful for multiple-endpoint nlmixr models. By default
#' this is determined by `option("rxode2.combine.dvid")` and if the option has not been set,
#' this is `TRUE`. This typically does not affect rxode2 simulations.
#'
#' @param keep This is a named vector of items you want to keep in the final rxode2 dataset.
#' For added rxode2 event records (if seen), last observation carried forward will be used.
#'
#' @inheritParams rxode2parse::etTransParse
#'
#' @return Object for solving in rxode2
#'
#' @keywords internal
#'
#' @export
etTrans <- function(inData, obj, addCmt = FALSE, dropUnits = FALSE, allTimeVar = FALSE, keepDosingOnly = FALSE, combineDvid = NULL, keep = character(0), addlKeepsCov = FALSE, addlDropSs = TRUE, ssAtDoseTime = TRUE) {
.Call(`_rxode2_etTrans`, inData, obj, addCmt, dropUnits, allTimeVar, keepDosingOnly, combineDvid, keep, addlKeepsCov, addlDropSs, ssAtDoseTime)
}
#' Expand grid internal function
#'
#' @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)
#' @export
#' @keywords internal
rxExpandGrid_ <- function(c1, c2, type) {
.Call(`_rxode2_rxExpandGrid_`, c1, c2, type)
}
#' Expand sensitivity
#'
#' @param state is the state to expand
#' @param calcSens is the variables to calculate sensitivity
#' @keywords internal
#' @return symengine string for expanded sensitivity
#' @export
rxExpandSens_ <- function(state, calcSens) {
.Call(`_rxode2_rxExpandSens_`, state, calcSens)
}
#' Expand second order sensitivity
#'
#' @param state is the state to expand
#' @param s1 is the variables to calculate sensitivity
#' @param s2 is the variables to calculate second order sensitivity
#' @keywords internal
#' @return string for symengine second order sensitivity
#' @export
rxExpandSens2_ <- function(state, s1, s2) {
.Call(`_rxode2_rxExpandSens2_`, state, s1, s2)
}
#' 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 isTheta logical, is the expansion actually for thetas instead of etas
#' @keywords internal
#' @return String of symengine expressions to evaluate to calculate df/deta
#' @export
rxExpandFEta_ <- function(state, neta, pred, isTheta = FALSE) {
.Call(`_rxode2_rxExpandFEta_`, state, neta, pred, isTheta)
}
#' Rep R0 for foce
#'
#' @param neta ETA to substitute
#'
#' @return Returns a string of R code to substitute the rx_r expression in the symengine environment .s
#'
#' @keywords internal
#'
#' @export
rxRepR0_ <- function(neta) {
.Call(`_rxode2_rxRepR0_`, neta)
}
rxExpandNesting <- function(obj, nestingInfo, compile = FALSE) {
.Call(`_rxode2_rxExpandNesting`, obj, nestingInfo, compile)
}
#' Inductive linearization solver
#'
#' @param cSub = Current subject number
#' @param op - rxode2 solving options
#' @param tp - Prior time point/time zero
#' @param yp - Prior state; vector size = neq; Final state is updated here
#' @param tf - Final Time
#' @param InfusionRate = Rates of each compartment; vector size = neq
#' @param on Indicator for if the compartment is "on"
#' @param cache
#' 0 = no Cache
#' When doIndLin == 0, cache > 0 = nInf-1
#' @param ME the rxode2 matrix exponential function
#' @param IndF The rxode2 Inductive Linearization function F
#'
#' @return Returns a status for solving
#'
#' 1 = Successful solve
#'
#' -1 = Maximum number of iterations reached when doing
#' inductive linearization
#' @name rxIndLin_
NULL
rxIndLin_ <- function(states) {
.Call(`_rxode2_rxIndLin_`, states)
}
#' Check the type of an object using Rcpp
#'
#' @param obj Object to check
#' @param cls Type of class. Only s3 classes for lists/environments and primitive classes are checked.
#' For matrix types they are distinguished as `numeric.matrix`, `integer.matrix`,
#' `logical.matrix`, and `character.matrix` as well as the traditional `matrix`
#' class. Additionally checks for `event.data.frame` which is an `data.frame` object
#' with `time`, `evid` and `amt`. (UPPER, lower or Title cases accepted)
#'
#' @return A boolean indicating if the object is a member of the class.
#'
#' @keywords internal
#'
#' @author Matthew L. Fidler
#'
#' @export
#'
rxIs <- function(obj, cls) {
.Call(`_rxode2_rxIs`, obj, cls)
}
getRxFn <- function(name) {
.Call(`_rxode2_getRxFn`, name)
}
dynLoad <- function(dll) {
.Call(`_rxode2_dynLoad`, dll)
}
rxModelVars_ <- function(obj) {
.Call(`_rxode2_rxModelVars_`, obj)
}
#' State variables
#'
#' This returns the model's compartments or states.
#'
#' @inheritParams rxModelVars
#'
#' @param state is a string indicating the state or compartment that
#' you would like to lookup.
#'
#' @return If state is missing, return a character vector of all the states.
#'
#' If state is a string, return the compartment number of the named state.
#'
#' @seealso [rxode2()]
#' @family Query model information
#' @author Matthew L.Fidler
#' @export
rxState <- function(obj = NULL, state = NULL) {
.Call(`_rxode2_rxState`, obj, state)
}
rxParams_ <- function(obj) {
.Call(`_rxode2_rxParams_`, obj)
}
#' Jacobian and parameter derivatives
#'
#' Return Jacobain and parameter derivatives
#'
#' @inheritParams rxModelVars
#'
#' @return A list of the jacobian parameters defined in this rxode2
#' object.
#'
#' @author Matthew L. Fidler
#'
#' @family Query model information
#' @export
rxDfdy <- function(obj) {
.Call(`_rxode2_rxDfdy`, obj)
}
#' Left handed Variables
#'
#' This returns the model calculated variables
#'
#' @inheritParams rxModelVars
#'
#' @return a character vector listing the calculated parameters
#' @seealso \code{\link{rxode2}}
#' @family Query model information
#' @author Matthew L.Fidler
#' @export
rxLhs <- function(obj) {
.Call(`_rxode2_rxLhs`, obj)
}
#' Initial Values and State values for a rxode2 object
#'
#' Returns the initial values of the rxDll object
#'
#' @param obj rxDll, rxode2, or named vector representing default
#' initial arguments
#'
#' @param vec If supplied, named vector for the model.
#'
#' @param req Required names, and the required order for the ODE solver
#'
#' @param defaultValue a number or NA representing the default value for
#' parameters missing in `vec`, but required in `req`.
#'
#' @param noerror is a boolean specifying if an error should be thrown
#' for missing parameter values when `default` = `NA`
#'
#' @return Initial values of the rxDll object
#'
#' @keywords internal
#' @family Query model information
#' @author Matthew L.Fidler
#' @export
rxInits <- function(obj, vec = NULL, req = NULL, defaultValue = 0, noerror = FALSE, noini = FALSE, rxLines = FALSE) {
.Call(`_rxode2_rxInits`, obj, vec, req, defaultValue, noerror, noini, rxLines)
}
#' Setup the initial conditions.
#'
#' @param obj rxode2 object
#' @param inits A numeric vector of initial conditions.
#' @return initial conditions that were setup
#' @author Matthew L. Fidler
#' @keywords internal
#' @export
rxSetupIni <- function(obj, inits = NULL) {
.Call(`_rxode2_rxSetupIni`, obj, inits)
}
#' Setup the initial conditions.
#'
#' @param obj rxode2 object
#'
#' @param scale A numeric vector scales
#'
#' @param extraArgs A list of extra args to parse for initial conditions.
#'
#' @author Matthew L. Fidler
#'
#' @keywords internal
#'
#' @return setup scale for changing compartment values
#'
#' @export
rxSetupScale <- function(obj, scale = NULL, extraArgs = NULL) {
.Call(`_rxode2_rxSetupScale`, obj, scale, extraArgs)
}
atolRtolFactor_ <- function(factor) {
invisible(.Call(`_rxode2_atolRtolFactor_`, factor))
}
#' Simulate Parameters from a Theta/Omega specification
#'
#' @param params Named Vector of rxode2 model parameters
#'
#' @param nObs Number of observations to simulate (with `sigma` matrix)
#'
#' @inheritParams rxSolve
#'
#' @param simSubjects boolean indicated rxode2 should simulate subjects in studies (`TRUE`,
#' default) or studies (`FALSE`)
#'
#' @return a data frame with the simulated subjects
#'
#' @author Matthew L.Fidler
#'
#' @export
rxSimThetaOmega <- function(params = NULL, omega = NULL, omegaDf = NULL, omegaLower = as.numeric( c(R_NegInf)), omegaUpper = as.numeric( c(R_PosInf)), omegaIsChol = FALSE, omegaSeparation = "auto", omegaXform = 1L, nSub = 1L, thetaMat = NULL, thetaLower = as.numeric( c(R_NegInf)), thetaUpper = as.numeric( c(R_PosInf)), thetaDf = NULL, thetaIsChol = FALSE, nStud = 1L, sigma = NULL, sigmaLower = as.numeric( c(R_NegInf)), sigmaUpper = as.numeric( c(R_PosInf)), sigmaDf = NULL, sigmaIsChol = FALSE, sigmaSeparation = "auto", sigmaXform = 1L, nCoresRV = 1L, nObs = 1L, dfSub = 0, dfObs = 0, simSubjects = TRUE, simVariability = as.logical( c(NA_LOGICAL))) {
.Call(`_rxode2_rxSimThetaOmega`, params, omega, omegaDf, omegaLower, omegaUpper, omegaIsChol, omegaSeparation, omegaXform, nSub, thetaMat, thetaLower, thetaUpper, thetaDf, thetaIsChol, nStud, sigma, sigmaLower, sigmaUpper, sigmaDf, sigmaIsChol, sigmaSeparation, sigmaXform, nCoresRV, nObs, dfSub, dfObs, simSubjects, simVariability)
}
#' Free the C solving/parsing information.
#'
#' Take the ODE C system and free it.
#'
#' @keywords internal
#' @return logical indicating if the memory was successfully freed
#' @export
rxSolveFree <- function() {
.Call(`_rxode2_rxSolveFree`)
}
#' See if the memory is installed for a solve
#'
#' @return boolean saying if the memnory is currently free for rxode2
#' @keywords internal
#' @export
#' @author Matthew L. Fidler
rxSolveSetup <- function() {
.Call(`_rxode2_rxSolveSetup`)
}
rxSolve_ <- function(obj, rxControl, specParams, extraArgs, params, events, inits, setupOnly) {
.Call(`_rxode2_rxSolve_`, obj, rxControl, specParams, extraArgs, params, events, inits, setupOnly)
}
rxSolveDollarNames <- function(obj) {
.Call(`_rxode2_rxSolveDollarNames`, obj)
}
rxSolveGet <- function(obj, arg, exact = TRUE) {
.Call(`_rxode2_rxSolveGet`, obj, arg, exact)
}
rxSolveUpdate <- function(obj, arg = NULL, value = NULL) {
.Call(`_rxode2_rxSolveUpdate`, obj, arg, value)
}
rxSolveSEXP <- function(objS, rxControlS, specParamsS, extraArgsS, paramsS, eventsS, initsS, setupOnlyS) {
.Call(`_rxode2_rxSolveSEXP`, objS, rxControlS, specParamsS, extraArgsS, paramsS, eventsS, initsS, setupOnlyS)
}
rxRmModelLib_ <- function(str) {
invisible(.Call(`_rxode2_rxRmModelLib_`, str))
}
#' Get rxode2 model from object
#' @param obj rxode2 family of objects
#' @return rxode2 model
#' @export
rxGetrxode2 <- function(obj) {
.Call(`_rxode2_rxGetrxode2`, obj)
}
#' Checks if the rxode2 object was built with the current build
#'
#' @inheritParams rxModelVars
#'
#' @return boolean indicating if this was built with current rxode2
#'
#' @export
rxIsCurrent <- function(obj) {
.Call(`_rxode2_rxIsCurrent`, obj)
}
#' Assign pointer based on model variables
#' @param object rxode2 family of objects
#' @return nothing, called for side effects
#' @export
rxAssignPtr <- function(object = NULL) {
invisible(.Call(`_rxode2_rxAssignPtr`, object))
}
#' Return the DLL associated with the rxode2 object
#'
#' This will return the dynamic load library or shared object used to
#' run the C code for rxode2.
#'
#' @param obj A rxode2 family of objects or a character string of the
#' model specification or location of a file with a model
#' specification.
#'
#' @return a path of the library
#'
#' @keywords internal
#' @author Matthew L.Fidler
#' @export
rxDll <- function(obj) {
.Call(`_rxode2_rxDll`, obj)
}
#' Return the C file associated with the rxode2 object
#'
#' This will return C code for generating the rxode2 DLL.
#'
#' @param obj A rxode2 family of objects or a character string of the
#' model specification or location of a file with a model
#' specification.
#'
#' @return a path of the library
#'
#' @keywords internal
#' @author Matthew L.Fidler
#' @export
rxC <- function(obj) {
.Call(`_rxode2_rxC`, obj)
}
#' Determine if the DLL associated with the rxode2 object is loaded
#'
#' @param obj A rxode2 family of objects
#'
#' @return Boolean returning if the rxode2 library is loaded.
#'
#' @keywords internal
#' @author Matthew L.Fidler
#' @export
rxIsLoaded <- function(obj) {
.Call(`_rxode2_rxIsLoaded`, obj)
}
#' Load rxode2 object
#'
#' @param obj A rxode2 family of objects
#'
#' @return Boolean returning if the rxode2 library is loaded.
#'
#' @keywords internal
#' @author Matthew L.Fidler
#' @export
rxDynLoad <- function(obj) {
.Call(`_rxode2_rxDynLoad`, obj)
}
#' Lock/unlocking of rxode2 dll file
#'
#' @param obj A rxode2 family of objects
#'
#' @return nothing; called for side effects
#'
#' @export
rxLock <- function(obj) {
.Call(`_rxode2_rxLock`, obj)
}
#' @rdname rxLock
#' @export
rxUnlock <- function(obj) {
.Call(`_rxode2_rxUnlock`, obj)
}
#' Allow unloading of dlls
#'
#' @param allow boolean indicating if garbage collection will unload of rxode2 dlls.
#'
#' @return Boolean allow; called for side effects
#'
#' @examples
#'
#' # Garbage collection will not unload un-used rxode2 dlls
#' rxAllowUnload(FALSE);
#'
#' # Garbage collection will unload unused rxode2 dlls
#' rxAllowUnload(TRUE);
#' @export
#' @author Matthew Fidler
rxAllowUnload <- function(allow) {
.Call(`_rxode2_rxAllowUnload`, allow)
}
rxUnloadAll_ <- function() {
.Call(`_rxode2_rxUnloadAll_`)
}
#' Unload rxode2 object
#'
#' @param obj A rxode2 family of objects
#'
#' @return Boolean returning if the rxode2 library is loaded.
#'
#' @keywords internal
#' @author Matthew L.Fidler
#' @export
rxDynUnload <- function(obj) {
.Call(`_rxode2_rxDynUnload`, obj)
}
#' Delete the DLL for the model
#'
#' This function deletes the DLL, but doesn't delete the model
#' information in the object.
#'
#' @param obj rxode2 family of objects
#'
#' @return A boolean stating if the operation was successful.
#'
#' @author Matthew L.Fidler
#' @export
rxDelete <- function(obj) {
.Call(`_rxode2_rxDelete`, obj)
}
setRstudio <- function(isRstudio = FALSE) {
.Call(`_rxode2_setRstudio`, isRstudio)
}
setProgSupported <- function(isSupported = 1L) {
.Call(`_rxode2_setProgSupported`, isSupported)
}
getProgSupported <- function() {
.Call(`_rxode2_getProgSupported`)
}
rxUpdateTrans_ <- function(ret, prefix, libName) {
.Call(`_rxode2_rxUpdateTrans_`, ret, prefix, libName)
}
dropUnitsRxSolve <- function(x) {
.Call(`_rxode2_dropUnitsRxSolve`, x)
}
#' Silence some of rxode2's C/C++ messages
#'
#' @param silent can be 0L "noisy" or 1L "silent"
#'
#' @keywords internal
#' @return TRUE; called for side effects
#' @export
rxSetSilentErr <- function(silent) {
.Call(`_rxode2_rxSetSilentErr`, silent)
}
#' Invert matrix using RcppArmadillo.
#'
#' @param matrix matrix to be inverted.
#'
#' @return inverse or pseudo inverse of matrix.
#'
#' @export
rxInv <- function(matrix) {
.Call(`_rxode2_rxInv`, matrix)
}
#' Get Omega^-1 and derivatives
#'
#' @param invObjOrMatrix Object for inverse-type calculations. If
#' this is a matrix, setup the object for inversion
#' [rxSymInvCholCreate()] with the default arguments and return a
#' reactive s3 object. Otherwise, use the inversion object to
#' calculate the requested derivative/inverse.
#'
#' @param theta Thetas to be used for calculation. If missing (`NULL`), a
#' special s3 class is created and returned to access `Omega^1`
#' objects as needed and cache them based on the theta that is
#' used.
#'
#' @param type The type of object. Currently the following types are
#' supported:
#'
#' * `cholOmegaInv` gives the
#' Cholesky decomposition of the Omega Inverse matrix.
#' * `omegaInv` gives the Omega Inverse matrix.
#' * `d(omegaInv)` gives the `d(Omega^-1)` withe respect to the
#' theta parameter specified in `thetaNumber`.
#' * `d(D)` gives the `d(diagonal(Omega^-1))` with respect to
#' the theta parameter specified in the `thetaNumber`
#' parameter
#'
#' @param thetaNumber For types `d(omegaInv)` and `d(D)`,
#' the theta number that the derivative is taken against. This
#' must be positive from 1 to the number of thetas defining the
#' Omega matrix.
#'
#' @return Matrix based on parameters or environment with all the
#' matrixes calculated in variables `omega`, `omegaInv`, `dOmega`,
#' `dOmegaInv`.
#'
#' @author Matthew L. Fidler
#'
#' @export
rxSymInvChol <- function(invObjOrMatrix, theta = NULL, type = "cholOmegaInv", thetaNumber = 0L) {
.Call(`_rxode2_rxSymInvChol`, invObjOrMatrix, theta, type, thetaNumber)
}
rxSymInvCholEnvCalculate <- function(obj, what, theta = NULL) {
.Call(`_rxode2_rxSymInvCholEnvCalculate`, obj, what, theta)
}
rxOptRep_ <- function(input) {
.Call(`_rxode2_rxOptRep_`, input)
}
isNullZero <- function(obj) {
.Call(`_rxode2_isNullZero`, obj)
}
rxErf <- function(v) {
.Call(`_rxode2_rxErf`, v)
}
binomProbsPredVec_ <- function(n, m, Y, M, doP = TRUE, tol = 1e-7) {
.Call(`_rxode2_binomProbsPredVec_`, n, m, Y, M, doP, tol)
}
binomProbs_ <- function(x, probs, naRm, nIn, cont) {
.Call(`_rxode2_binomProbs_`, x, probs, naRm, nIn, cont)
}
meanProbs_ <- function(x, probs, naRm, useT, pred, nIn) {
.Call(`_rxode2_meanProbs_`, x, probs, naRm, useT, pred, nIn)
}