|
4 | 4 | #' The function is compatible with the class \link{omics} method \code{composition()}. |
5 | 5 | #' |
6 | 6 | #' @param data A \link[base]{data.frame} or \link[data.table]{data.table}. |
7 | | -#' @param palette An object with names and hexcode or color names, see \link{colormap}. |
8 | | -#' @param feature_rank A character variable of the feature column. |
9 | | -#' @param title_name A character to set the \code{ggtitle} of the \link[ggplot2]{ggplot}, (Default: NULL). |
10 | | -#' @param group_by A character variable to aggregate the stacked bars by group (Default: NULL). |
| 7 | +#' @param palette A \link[stats]{setNames}, see \link{colormap}. |
| 8 | +#' @param feature_rank A column name containing the feature names. |
| 9 | +#' @param title_name A character to set the \code{ggtitle} of the \link[ggplot2]{ggplot}, (default: \code{NULL}). |
| 10 | +#' @param group_by A character variable to aggregate the stacked bars by group (default: \code{NULL}). |
11 | 11 | #' @return A \link[ggplot2]{ggplot2} object to be further modified |
12 | 12 | #' |
13 | 13 | #' @examples |
@@ -75,30 +75,33 @@ composition_plot <- function(data, |
75 | 75 | #--------------------------------------------------------------------# |
76 | 76 |
|
77 | 77 | if (!inherits(data, "data.frame") && !inherits(data, "data.table")) |
78 | | - cli::cli_abort("Data must be a {.cls data.frame} or {.cls data.table}.") |
| 78 | + cli::cli_abort("{.val data} must be a {.cls data.frame} or {.cls data.table}.") |
79 | 79 |
|
80 | 80 | if (!is.character(palette)) |
81 | | - cli::cli_abort("{.val {palette}} needs to contain characters.") |
| 81 | + cli::cli_abort("{.val palette} needs to contain characters.") |
82 | 82 |
|
83 | | - if (!is.character(feature_rank) && length(feature_rank) != 1) { |
84 | | - cli::cli_abort("{.val {feature_rank}} needs to contain characters with length of 1.") |
| 83 | + if (!is.character(feature_rank) || length(feature_rank) != 1) { |
| 84 | + cli::cli_abort("{.val feature_rank} needs to contain characters with length of 1.") |
85 | 85 | } else if (!column_exists(feature_rank, data)) { |
86 | | - cli::cli_abort("The {.val {feature_rank}} column does not exist in the provided {.arg data}.") |
| 86 | + cli::cli_abort("The {.val {feature_rank}} column does not exist in the provided {.val data}.") |
87 | 87 | } |
88 | 88 |
|
89 | | - if (!is.null(title_name) && !is.character(title_name)) |
90 | | - cli::cli_abort("{.val {title_name}} needs to be of type character.") |
| 89 | + if (!is.null(title_name)) { |
| 90 | + if (!is.character(title_name) || length(title_name) != 1) { |
| 91 | + cli::cli_abort("{.val title_name} must be a character and of length 1") |
| 92 | + } |
| 93 | + } |
91 | 94 |
|
92 | 95 | if (!is.null(group_by)) { |
93 | | - if (!is.character(group_by) && length(group_by) != 1) { |
94 | | - cli::cli_abort("{.val {group_by}} must be a character and of length 1") |
| 96 | + if (!is.character(group_by) || length(group_by) != 1) { |
| 97 | + cli::cli_abort("{.val group_by} must be a character and of length 1") |
95 | 98 | } else if (!column_exists(group_by, data)) { |
96 | | - cli::cli_abort("The specified {.val {group_by}} does not exist in the provided {.arg data}.") |
| 99 | + cli::cli_abort("The specified {.val {group_by}} does not exist in the provided {.val data}.") |
97 | 100 | } |
98 | 101 | } |
99 | 102 |
|
100 | 103 | if (!column_exists("SAMPLE_ID", data)) |
101 | | - cli::cli_abort("{.arg SAMPLE_ID} needs to exist within the provided {.arg data}.") |
| 104 | + cli::cli_abort("{.arg SAMPLE_ID} needs to exist within the provided {.val data}.") |
102 | 105 |
|
103 | 106 | ## MAIN |
104 | 107 | #--------------------------------------------------------------------# |
|
0 commit comments