-
Notifications
You must be signed in to change notification settings - Fork 2
Fix bug for multiple variables in observation #46
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -25,6 +25,8 @@ | |||||||||||||||||||||||||||||||||
| #' The term name is used as key to link information. | ||||||||||||||||||||||||||||||||||
| #' @param analysis A character value of analysis term name. | ||||||||||||||||||||||||||||||||||
| #' The term name is used as key to link information. | ||||||||||||||||||||||||||||||||||
| #' @param filter_var A character value of variable name used for filtering. | ||||||||||||||||||||||||||||||||||
| #' Default is "PARAM". | ||||||||||||||||||||||||||||||||||
| #' @param hover_var_outlier A character vector of hover variables for outlier. | ||||||||||||||||||||||||||||||||||
| #' | ||||||||||||||||||||||||||||||||||
| #' @return Metadata list with plotting dataset. | ||||||||||||||||||||||||||||||||||
|
|
@@ -48,6 +50,7 @@ prepare_boxly <- function(meta, | |||||||||||||||||||||||||||||||||
| population = NULL, | ||||||||||||||||||||||||||||||||||
| observation = NULL, | ||||||||||||||||||||||||||||||||||
| analysis = NULL, | ||||||||||||||||||||||||||||||||||
| filter_var = "PARAM", | ||||||||||||||||||||||||||||||||||
| hover_var_outlier = c("USUBJID", metalite::collect_adam_mapping(meta, analysis)$y)) { | ||||||||||||||||||||||||||||||||||
| if (is.null(population)) { | ||||||||||||||||||||||||||||||||||
| if (length(meta$population) == 1) { | ||||||||||||||||||||||||||||||||||
|
|
@@ -109,11 +112,23 @@ prepare_boxly <- function(meta, | |||||||||||||||||||||||||||||||||
| obs[[obs_group]] <- factor(obs[[obs_group]], levels = sort(unique(obs[[obs_group]]))) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (!"factor" %in% class(obs[[obs_var]])) { | ||||||||||||||||||||||||||||||||||
| message("In observation level data, the facet variable '", obs_var, "' is automatically transformed into a factor.") | ||||||||||||||||||||||||||||||||||
| obs[[obs_var]] <- factor(obs[[obs_var]], levels = sort(unique(obs[[obs_var]]))) | ||||||||||||||||||||||||||||||||||
| if (!filter_var %in% obs_var) { | ||||||||||||||||||||||||||||||||||
| stop(paste( | ||||||||||||||||||||||||||||||||||
| "The filter variable '", filter_var, "' is not found in the observation data.", | ||||||||||||||||||||||||||||||||||
| "Please check the metadata for observation and `filter_var`." | ||||||||||||||||||||||||||||||||||
| )) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| obs[, obs_var] <- lapply(obs_var, function(var) { | ||||||||||||||||||||||||||||||||||
| x <- obs[[var]] | ||||||||||||||||||||||||||||||||||
| if (!is.factor(x)) { | ||||||||||||||||||||||||||||||||||
| message("In observation level data, the facet variable '", var, "' is automatically transformed into a factor.") | ||||||||||||||||||||||||||||||||||
| factor(x, levels = sort(unique(x))) | ||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||
| x | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+122
to
+130
|
||||||||||||||||||||||||||||||||||
| obs[, obs_var] <- lapply(obs_var, function(var) { | |
| x <- obs[[var]] | |
| if (!is.factor(x)) { | |
| message("In observation level data, the facet variable '", var, "' is automatically transformed into a factor.") | |
| factor(x, levels = sort(unique(x))) | |
| } else { | |
| x | |
| } | |
| }) | |
| for (var in obs_var) { | |
| x <- obs[[var]] | |
| if (!is.factor(x)) { | |
| message("In observation level data, the facet variable '", var, "' is automatically transformed into a factor.") | |
| obs[[var]] <- factor(x, levels = sort(unique(x))) | |
| } | |
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message uses inconsistent spacing in the
paste()function, resulting in extra spaces around the filter variable name in the output. Remove the trailing space after the filter_var placeholder:Should be:
Using
paste0()gives better control over spacing.