Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix factors crash in tm_g_association #692

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/tm_g_association.R
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ srv_tm_g_association <- function(id,
teal::validate_has_data(ANL[, c(ref_name, vars_names)], 3, complete = TRUE, allow_inf = FALSE)

# reference
ref_class <- class(ANL[[ref_name]])
ref_class <- class(ANL[[ref_name]])[1]
vedhav marked this conversation as resolved.
Show resolved Hide resolved
if (is.numeric(ANL[[ref_name]]) && log_transformation) {
# works for both integers and doubles
ref_cl_name <- call("log", as.name(ref_name))
Expand Down Expand Up @@ -373,7 +373,7 @@ srv_tm_g_association <- function(id,
print_call <- quote(print(p))

var_calls <- lapply(vars_names, function(var_i) {
var_class <- class(ANL[[var_i]])
var_class <- class(ANL[[var_i]])[1]
vedhav marked this conversation as resolved.
Show resolved Hide resolved
if (is.numeric(ANL[[var_i]]) && log_transformation) {
# works for both integers and doubles
var_cl_name <- call("log", as.name(var_i))
Expand Down
41 changes: 23 additions & 18 deletions R/tm_g_bivariate.R
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ bivariate_plot_call <- function(data_name,
alpha = double(0),
size = 2,
ggplot2_args = teal.widgets::ggplot2_args()) {
supported_types <- c("NULL", "numeric", "integer", "factor", "character", "logical")
supported_types <- c("NULL", "numeric", "integer", "factor", "character", "logical", "ordered")
validate(need(x_class %in% supported_types, paste0("Data type '", x_class, "' is not supported.")))
validate(need(y_class %in% supported_types, paste0("Data type '", y_class, "' is not supported.")))

Expand Down Expand Up @@ -797,8 +797,8 @@ substitute_q <- function(x, env) {
#' bivariate_ggplot_call("numeric", "factor")
#' bivariate_ggplot_call("factor", "numeric")
#' bivariate_ggplot_call("factor", "factor")
bivariate_ggplot_call <- function(x_class = c("NULL", "numeric", "integer", "factor", "character", "logical"),
y_class = c("NULL", "numeric", "integer", "factor", "character", "logical"),
bivariate_ggplot_call <- function(x_class,
y_class,
freq = TRUE,
theme = "gray",
rotate_xaxis_labels = FALSE,
Expand All @@ -811,21 +811,26 @@ bivariate_ggplot_call <- function(x_class = c("NULL", "numeric", "integer", "fac
ylab = "-",
data_name = "ANL",
ggplot2_args = teal.widgets::ggplot2_args()) {
x_class <- match.arg(x_class)
y_class <- match.arg(y_class)

if (x_class %in% c("character", "logical")) {
x_class <- "factor"
}
if (x_class %in% c("integer")) {
x_class <- "numeric"
}
if (y_class %in% c("character", "logical")) {
y_class <- "factor"
}
if (y_class %in% c("integer")) {
y_class <- "numeric"
}
x_class <- switch(x_class,
"character" = ,
"ordered" = ,
"logical" = ,
"factor" = "factor",
"integer" = ,
"numeric" = "numeric",
"NULL" = "NULL",
stop("unsupported x_class: ", x_class)
)
y_class <- switch(y_class,
"character" = ,
"ordered" = ,
"logical" = ,
"factor" = "factor",
"integer" = ,
"numeric" = "numeric",
"NULL" = "NULL",
stop("unsupported y_class: ", y_class)
)

if (all(c(x_class, y_class) == "NULL")) {
stop("either x or y is required")
Expand Down
Loading