Skip to content

Commit

Permalink
Add rename for thetaMat and sigma if present
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Dec 8, 2023
1 parent 8665e32 commit 386cd10
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions R/ui-rename.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,34 @@
stop("unknown expression", call.=FALSE)
}
}
#' Rename all items in matrix dimnames
#'
#' @param mat matrix
#' @param lst list for renaming
#' @return renamed matrix
#' @noRd
#' @author Matthew L. Fidler
.rxRenameAllMat <- function(mat, lst) {
.d <- dimnames(mat)[[1]]
.d <- vapply(seq_along(.d), function(i) {
.env <- new.env(parent=emptyenv())
.env$new <- NULL
.cur <- .d[i]
lapply(seq_along(lst),
function(j) {
if (!is.null(.env$new)) return(NULL)
.curLst <- lst[[j]]
.old <- .curLst[[4]]
if (.cur == .old) {
.env$new <- .curLst[[3]]

Check warning on line 131 in R/ui-rename.R

View check run for this annotation

Codecov / codecov/patch

R/ui-rename.R#L120-L131

Added lines #L120 - L131 were not covered by tests
}
})
if (!is.null(.env$new)) return(.env$new)
return(.cur)
}, character(1), USE.NAMES=FALSE)
dimnames(mat) <- list(.d, .d)
mat

Check warning on line 138 in R/ui-rename.R

View check run for this annotation

Codecov / codecov/patch

R/ui-rename.R#L134-L138

Added lines #L134 - L138 were not covered by tests
}

#' Rename all the items in the initialization data frame and model
#'
Expand Down Expand Up @@ -137,6 +165,21 @@
return(.cur)
}, character(1), USE.NAMES=FALSE)
rxui$iniDf <- .iniDf
if (exists("sigma", rxui)) {
assign("sigma", .rxRenameAllMat(get("sigma", envir=rxui), lst), envir=rxui)

Check warning on line 169 in R/ui-rename.R

View check run for this annotation

Codecov / codecov/patch

R/ui-rename.R#L169

Added line #L169 was not covered by tests
}
if (exists("thetaMat", rxui)) {
assign("thetaMat", .rxRenameAllMat(get("thetaMat", envir=rxui), lst), envir=rxui)

Check warning on line 172 in R/ui-rename.R

View check run for this annotation

Codecov / codecov/patch

R/ui-rename.R#L172

Added line #L172 was not covered by tests
}
if (exists("meta", rxui)) {
.meta <- get("meta", rxui)
if (exists("sigma", .meta)) {
assign("sigma", .rxRenameAllMat(get("sigma", envir=rxui), lst), envir=.meta)

Check warning on line 177 in R/ui-rename.R

View check run for this annotation

Codecov / codecov/patch

R/ui-rename.R#L177

Added line #L177 was not covered by tests
}
if (exists("thetaMat", .meta)) {
assign("thetaMat", .rxRenameAllMat(get("thetaMat", envir=rxui), lst), envir=.meta)

Check warning on line 180 in R/ui-rename.R

View check run for this annotation

Codecov / codecov/patch

R/ui-rename.R#L180

Added line #L180 was not covered by tests
}
}
rxui$lstExpr <- lapply(seq_along(rxui$lstExpr),
function(i) {
.rxRenameRecursiveAll(rxui$lstExpr[[i]], lst=lst)
Expand Down

0 comments on commit 386cd10

Please sign in to comment.