Skip to content

Commit

Permalink
Add a modifying function for raw rxUi objects (& tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Nov 29, 2023
1 parent 01eaf76 commit 2b0238b
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 61 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ S3method("$",rxSymInvCholEnv)
S3method("$",rxUi)
S3method("$<-",rxSolve)
S3method("$<-",rxSymInvCholEnv)
S3method("$<-",rxUi)
S3method("+",rxSolve)
S3method("+",solveRxDll)
S3method("[",rxSolve)
Expand Down Expand Up @@ -139,6 +140,7 @@ S3method(rxUiGet,lhsTheta)
S3method(rxUiGet,lhsVar)
S3method(rxUiGet,lstChr)
S3method(rxUiGet,md5)
S3method(rxUiGet,model)
S3method(rxUiGet,modelDesc)
S3method(rxUiGet,modelFun)
S3method(rxUiGet,muRefTable)
Expand Down
17 changes: 15 additions & 2 deletions R/rxUiGet.R
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ rxUiGet.iniFun <- function(x, ...) {
}
attr(rxUiGet.iniFun, "desc") <- "normalized, quoted `ini()` block"


#' @export
#' @rdname rxUiGet
rxUiGet.modelFun <- function(x, ...) {
Expand All @@ -243,6 +244,11 @@ rxUiGet.modelFun <- function(x, ...) {
}
attr(rxUiGet.modelFun, "desc") <- "normalized, quoted `model()` block"

#' @export
#' @rdname rxUiGet
rxUiGet.model <- rxUiGet.modelFun


#' @export
#' @rdname rxUiGet
rxUiGet.modelDesc <- function(x, ...) {
Expand Down Expand Up @@ -365,8 +371,15 @@ attr(rxUiGet.covLhs, "desc") <- "cov->lhs translation"
#' @rdname rxUiGet
rxUiGet.default <- function(x, ...) {
.arg <- class(x)[1]
if (!exists(.arg, envir=x[[1]])) return(NULL)
get(.arg, x[[1]])
.ui <- x[[1]]
if (!exists(.arg, envir=.ui)) {
.meta <- get("meta", envir=.ui)
if (exists(.arg, envir=.meta)) {
return(get(.arg, envir=.meta))
}
return(NULL)
}
get(.arg, .ui)
}

.rxUiGetEnvInfo <- c("model"="Original Model (with comments if available)",
Expand Down
27 changes: 27 additions & 0 deletions R/ui-assign-parts.R
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,30 @@
`RxODE<-` <- function(x, envir=environment(x), value) {
UseMethod("rxode2<-")
}

#' @export
`$<-.rxUi` <- function(x, name, value) {
.raw <- inherits(x, "raw")
if (!.raw) {
assign(name, value, envir=x)
return(x)
}
.x <- x
if (name %in% c("ini", "iniDf")) {
ini(x) <- value
return(x)
}
if (name == "model") {
model(x) <- value
return(x)
}
.x <- rxUiDecompress(.x)
if (exists(name, .x)) {
stop("'", name, "' is a fixed UI component and should not be overwritten",
call.=FALSE)
}
.meta <- get("meta", .x)
assign(name, value, envir=.meta)
.x <- rxUiCompress(.x)
.x
}
1 change: 1 addition & 0 deletions man/reexports.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/rxUiGet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/rxode2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2b0238b

Please sign in to comment.