Skip to content

Commit

Permalink
Bug fixes for getting and copyUi
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Jul 30, 2024
1 parent e8b34f9 commit e50f87e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
4 changes: 3 additions & 1 deletion R/piping-ini.R
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,9 @@ ini.rxUi <- function(x, ..., envir=parent.frame(), append = NULL) {
.ret <- rxUiDecompress(.copyUi(x)) # copy so (as expected) old UI isn't affected by the call
.iniDf <- .ret$iniDf
.iniLines <- .quoteCallInfoLines(match.call(expand.dots = TRUE)[-(1:2)], envir=envir, iniDf= .iniDf)
if (length(.iniLines) == 0L) return(.ret$iniFun)
if (length(.iniLines) == 0L) {
return(.ret$iniFun)
}
lapply(.iniLines, function(line) {
.iniHandleLine(expr = line, rxui = .ret, envir = envir, append=append)
})
Expand Down
18 changes: 14 additions & 4 deletions R/piping.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@
if (inherits(ui, "raw")) {
return(rxUiDecompress(ui))
}
.ret <- new.env(parent=emptyenv())
lapply(ls(envir=ui, all.names=TRUE), function(item){
assign(item, get(item, envir=ui), envir=.ret)
})
if (is.environment(ui)) {
.ret <- new.env(parent=emptyenv())
lapply(ls(envir=ui, all.names=TRUE), function(item){
assign(item, get(item, envir=ui), envir=.ret)
})
} else if (is.list(ui)) {
.n <- names(ui)
.ret <- lapply(.n, function(item){
ui[[item]]
})
names(.ret) <- .n
} else {
stop("ui must be a list or environment")
}
class(.ret) <- class(ui)
.ret
}
Expand Down
19 changes: 12 additions & 7 deletions R/rxUiGet.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ rxUiExists <- function(x, envir) {
#' @export
#' @keywords internal
#' @author Matthew L. Fidler
getRxUiRo <- function(x, ui) {
if (is.environment(ui)) {
get(x, envir=ui)
} else if (is.list(ui)) {
.ui <- ui
getRxUiRo <- function(x, envir) {
if (is.environment(envir)) {
if (exists(x, envir=envir)) {
get(x, envir=envir)
} else {
NULL
}
} else if (is.list(envir)) {
.ui <- envir
class(.ui) <- NULL
.ui[[x]]
} else {
stop("ui must be an environment or list for getRxUiRo()")
}
}

Expand Down Expand Up @@ -489,6 +491,9 @@ rxUiGet.default <- function(x, ...) {
.ui <- x[[1]]
if (!rxUiExists(.arg, envir=.ui)) {
.meta <- getRxUiRo("meta", envir=.ui)
if (is.null(.meta)) {
return(NULL)
}
if (is.environment(.meta)) {
if (exists(.arg, envir=.meta)) {
return(getRxUiRo(.arg, envir=.meta))
Expand Down
3 changes: 3 additions & 0 deletions R/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,9 @@ rxUiCompress <- function(ui, type=c("list","qs")) {
}
if (is.environment(ui) && type=="list") {
.m <- get("meta", envir=ui)
if (is.null(.m)) {
.m <- new.env(parent=emptyenv())
}
.n <- ls(get("meta", envir=ui), all=TRUE)
.meta <- lapply(.n, function(x) {
get(x, .m)
Expand Down

0 comments on commit e50f87e

Please sign in to comment.