Skip to content

Commit

Permalink
Add .uiArg
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Dec 13, 2024
1 parent 369886d commit aec078a
Showing 1 changed file with 22 additions and 30 deletions.
52 changes: 22 additions & 30 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -508,53 +508,45 @@ expit <- function(alpha, low = 0, high = 1) {
}


.uiArg <- function(char, f) {
if (!inherits(f, "try-error")) {
if (is.numeric(f)) {
return(as.character(f))
}
if (is.character(f)) {
return(f)
}
}
char
}

.logit <- function(x, low = 0, high=1) {
.x <- as.character(substitute(x))
.tmp <- suppressWarnings(try(force(x), silent = TRUE))
if (!inherits(.tmp, "try-error")) {
if (is.character(.tmp) || is.numeric(.tmp)) {
.x <- x
}
}
.x <- .uiArg(.x, .tmp)

.low <- as.character(substitute(low))
.tmp <- suppressWarnings(try(force(low), silent = TRUE))
if (!inherits(.tmp, "try-error")) {
if (is.character(.tmp) || is.numeric(.tmp)) {
.low <- low
}
}
.low <- .uiArg(.low, .tmp)

.high <- as.character(substitute(high))
.tmp <- suppressWarnings(try(force(high), silent = TRUE))
if (!inherits(.tmp, "try-error")) {
if (is.character(.tmp) || is.numeric(.tmp)) {
.high <- high
}
}
.high <- .uiArg(.high, .tmp)
list(replace = paste0("logit(", .x, ", ", .low, ", ", .high, ")"))
}

.expit <- function(x, low = 0, high=1) {
.x <- as.character(substitute(x))
.tmp <- suppressWarnings(try(force(x), silent = TRUE))
if (!inherits(.tmp, "try-error")) {
if (is.character(.tmp) || is.numeric(.tmp)) {
.x <- x
}
}
.x <- .uiArg(.x, .tmp)

.low <- as.character(substitute(low))
.tmp <- suppressWarnings(try(force(low), silent = TRUE))
if (!inherits(.tmp, "try-error")) {
if (is.character(.tmp) || is.numeric(.tmp)) {
.low <- low
}
}
.low <- .uiArg(.low, .tmp)

.high <- as.character(substitute(high))
.tmp <- suppressWarnings(try(force(high), silent = TRUE))
if (!inherits(.tmp, "try-error")) {
if (is.character(.tmp) || is.numeric(.tmp)) {
.high <- high
}
}
.high <- .uiArg(.high, .tmp)
list(replace = paste0("expit(", .x, ", ", .low, ", ", .high, ")"))
}

Expand Down

0 comments on commit aec078a

Please sign in to comment.