From d6647c480180f51c63d35369668b7935bcb50c02 Mon Sep 17 00:00:00 2001 From: John Ehrlinger Date: Mon, 23 Jun 2025 12:12:26 -0400 Subject: [PATCH] Cleanup gg_partial --- NAMESPACE | 4 +- R/{gg_partial_df.R => gg_partial.R} | 40 +++++++++---------- R/{gg_partialpro_df.R => gg_partialpro.R} | 22 +++++----- man/{gg_partial_df.Rd => gg_partial.Rd} | 12 +++--- man/{gg_partialpro_df.Rd => gg_partialpro.Rd} | 12 +++--- 5 files changed, 43 insertions(+), 47 deletions(-) rename R/{gg_partial_df.R => gg_partial.R} (65%) rename R/{gg_partialpro_df.R => gg_partialpro.R} (86%) rename man/{gg_partial_df.Rd => gg_partial.Rd} (66%) rename man/{gg_partialpro_df.Rd => gg_partialpro.Rd} (65%) diff --git a/NAMESPACE b/NAMESPACE index 6673e90..b7434d2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -26,8 +26,8 @@ export(gg_error) export(gg_error.randomForest) export(gg_error.randomForest.formula) export(gg_error.rfsrc) -export(gg_partial_df) -export(gg_partialpro_df) +export(gg_partial) +export(gg_partialpro) export(gg_rfsrc) export(gg_roc) export(gg_survival) diff --git a/R/gg_partial_df.R b/R/gg_partial.R similarity index 65% rename from R/gg_partial_df.R rename to R/gg_partial.R index 57bf189..2ac586e 100644 --- a/R/gg_partial_df.R +++ b/R/gg_partial.R @@ -2,13 +2,16 @@ #' Split partial lots into continuous or categorical datasets #' @param part_dta partial plot data from \code{rfsrc::plot.variable} #' @param nvars how many of the partial plot variables to calculate -#' @param cat_limit Categorical features are build when there are fewer than +#' @param cat_limit Categorical features are build when there are fewer than #' cat_limit unique features. -#' @param name a label name applied to all features. Useful when combining +#' @param model a label name applied to all features. Useful when combining #' multiple partial plot objects in figures. -#' +#' #' @export -gg_partial_df = function(part_dta, nvars = NULL, cat_limit = 10, name=NULL) { +gg_partial = function(part_dta, + nvars = NULL, + cat_limit = 10, + model = NULL) { ## Prepare the partial dependencies data for panel plots if (is.null(nvars)) { nvars = length(part_dta$plotthis) @@ -19,12 +22,10 @@ gg_partial_df = function(part_dta, nvars = NULL, cat_limit = 10, name=NULL) { for (feature in seq(nvars)) { ## Format any continuous features (those with fewer than cat_limit unique values) if (length(unique(part_dta$plotthis[[feature]]$x)) > cat_limit) { - plt.df = as.data.frame( - cbind( - x = part_dta$plotthis[[feature]]$x, - yhat = part_dta$plotthis[[feature]]$yhat - ) - ) + plt.df = as.data.frame(cbind( + x = part_dta$plotthis[[feature]]$x, + yhat = part_dta$plotthis[[feature]]$yhat + )) plt.df$name = names(part_dta$plotthis)[[feature]] cont_list[[feature]] <- plt.df @@ -33,12 +34,10 @@ gg_partial_df = function(part_dta, nvars = NULL, cat_limit = 10, name=NULL) { ## Though VarPro works with logical or continuous only. Factors are ## one hot encoded internal to the varPro call. - plt.df = as.data.frame( - cbind( - x = factor(part_dta$plotthis[[feature]]$x), - yhat = part_dta$plotthis[[feature]]$yhat - ) - ) + plt.df = as.data.frame(cbind( + x = factor(part_dta$plotthis[[feature]]$x), + yhat = part_dta$plotthis[[feature]]$yhat + )) plt.df$name = names(part_dta$plotthis)[[feature]] cat_list[[feature]] <- plt.df @@ -47,12 +46,9 @@ gg_partial_df = function(part_dta, nvars = NULL, cat_limit = 10, name=NULL) { continuous = dplyr::bind_rows(cont_list) categorical = dplyr::bind_rows(cat_list) - if(!is.na(name)){ - continuous$model <- categorical$model <- name + if (!is.null(model)) { + continuous$model <- categorical$model <- model } - return(list( - continuous = continuous, - categorical = categorical - )) + return(list(continuous = continuous, categorical = categorical)) } \ No newline at end of file diff --git a/R/gg_partialpro_df.R b/R/gg_partialpro.R similarity index 86% rename from R/gg_partialpro_df.R rename to R/gg_partialpro.R index 62db225..5b318a4 100644 --- a/R/gg_partialpro_df.R +++ b/R/gg_partialpro.R @@ -3,14 +3,17 @@ #' Split partial lots into continuous or categorical datasets #' @param part_dta partial plot data from \code{varpro::partialpro} #' @param nvars how many of the partial plot variables to calculate -#' @param cat_limit Categorical features are build when there are fewer than +#' @param cat_limit Categorical features are build when there are fewer than #' cat_limit unique features. -#' @param name a label name applied to all features. Useful when combining +#' @param model a label name applied to all features. Useful when combining #' multiple partial plot objects in figures. -#' +#' #' @export -#' -gg_partialpro_df = function(part_dta, nvars = NULL, cat_limit=10, name=NULL) { +#' +gg_partialpro = function(part_dta, + nvars = NULL, + cat_limit = 10, + model = NULL) { ## Prepare the partial pro dependencies data for panel plots if (is.null(nvars)) { nvars = length(part_dta) @@ -68,12 +71,9 @@ gg_partialpro_df = function(part_dta, nvars = NULL, cat_limit=10, name=NULL) { continuous = dplyr::bind_rows(cont_list) categorical = dplyr::bind_rows(cat_list) - if(!is.na(name)){ - continuous$model <- categorical$model <- name + if (!is.null(model)) { + continuous$model <- categorical$model <- model } - return(list( - continuous = continuous, - categorical = categorical - )) + return(list(continuous = continuous, categorical = categorical)) } \ No newline at end of file diff --git a/man/gg_partial_df.Rd b/man/gg_partial.Rd similarity index 66% rename from man/gg_partial_df.Rd rename to man/gg_partial.Rd index e580687..60ed0bf 100644 --- a/man/gg_partial_df.Rd +++ b/man/gg_partial.Rd @@ -1,20 +1,20 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/gg_partial_df.R -\name{gg_partial_df} -\alias{gg_partial_df} +% Please edit documentation in R/gg_partial.R +\name{gg_partial} +\alias{gg_partial} \title{Split partial lots into continuous or categorical datasets} \usage{ -gg_partial_df(part_dta, nvars = NULL, cat_limit = 10, name = NULL) +gg_partial(part_dta, nvars = NULL, cat_limit = 10, model = NULL) } \arguments{ \item{part_dta}{partial plot data from \code{rfsrc::plot.variable}} \item{nvars}{how many of the partial plot variables to calculate} -\item{cat_limit}{Categorical features are build when there are fewer than +\item{cat_limit}{Categorical features are build when there are fewer than cat_limit unique features.} -\item{name}{a label name applied to all features. Useful when combining +\item{model}{a label name applied to all features. Useful when combining multiple partial plot objects in figures.} } \description{ diff --git a/man/gg_partialpro_df.Rd b/man/gg_partialpro.Rd similarity index 65% rename from man/gg_partialpro_df.Rd rename to man/gg_partialpro.Rd index a2ab81c..e24c53a 100644 --- a/man/gg_partialpro_df.Rd +++ b/man/gg_partialpro.Rd @@ -1,20 +1,20 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/gg_partialpro_df.R -\name{gg_partialpro_df} -\alias{gg_partialpro_df} +% Please edit documentation in R/gg_partialpro.R +\name{gg_partialpro} +\alias{gg_partialpro} \title{Split partial lots into continuous or categorical datasets} \usage{ -gg_partialpro_df(part_dta, nvars = NULL, cat_limit = 10, name = NULL) +gg_partialpro(part_dta, nvars = NULL, cat_limit = 10, model = NULL) } \arguments{ \item{part_dta}{partial plot data from \code{varpro::partialpro}} \item{nvars}{how many of the partial plot variables to calculate} -\item{cat_limit}{Categorical features are build when there are fewer than +\item{cat_limit}{Categorical features are build when there are fewer than cat_limit unique features.} -\item{name}{a label name applied to all features. Useful when combining +\item{model}{a label name applied to all features. Useful when combining multiple partial plot objects in figures.} } \description{