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

update g_lineplot code to handle special characters #1230

Merged
merged 6 commits into from
Apr 26, 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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# tern 0.9.4.9002

### Enhancements
* Added `facet_var` to `g_lineplot` to allow plot faceting by a factor variable.
* Updated `g_lineplot` legend to follow factor levels set by users.
* Added examples and tests for `label_all` parameter to `extract_survival_biomarkers` and `extract_survival_subgroups`.

### Miscellaneous
Expand Down
20 changes: 13 additions & 7 deletions R/g_lineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,15 @@ g_lineplot <- function(df,
df_N[[strata_N]] <- paste0(df_N[[group_var]], " (N = ", df_N$N, ")") # nolint

# keep strata factor levels
matches <- sapply(unique(df_N[[group_var]]),
function(x) unique(df_N[[paste0(group_var, "_N")]]) #nolint
[grepl(paste0("^", x), unique(df_N[[paste0(group_var, "_N")]]))])
df_N[[paste0(group_var, "_N")]] <- factor(df_N[[group_var]]) #nolint
levels(df_N[[paste0(group_var, "_N")]]) <- unlist(matches) #nolint
matches <- sapply(unique(df_N[[group_var]]), function(x) {
regex_pattern <- gsub("([][(){}^$.|*+?\\\\])", "\\\\\\1", x)
unique(df_N[[paste0(group_var, "_N")]])[grepl(
paste0("^", regex_pattern),
unique(df_N[[paste0(group_var, "_N")]])
)]
})
df_N[[paste0(group_var, "_N")]] <- factor(df_N[[group_var]]) # nolint
levels(df_N[[paste0(group_var, "_N")]]) <- unlist(matches) # nolint

# strata_N should not be in colnames(df_stats)
checkmate::assert_disjunct(strata_N, colnames(df_stats))
Expand Down Expand Up @@ -551,7 +555,9 @@ control_lineplot_vars <- function(x = "AVISIT",
checkmate::assert_string(paramcd, na.ok = TRUE, null.ok = TRUE)
checkmate::assert_string(y_unit, na.ok = TRUE, null.ok = TRUE)

variables <- c(x = x, y = y, group_var = group_var, paramcd = paramcd,
y_unit = y_unit, subject_var = subject_var, facet_var = facet_var)
variables <- c(
x = x, y = y, group_var = group_var, paramcd = paramcd,
y_unit = y_unit, subject_var = subject_var, facet_var = facet_var
)
return(variables)
}
Loading
Loading