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

381 pare down the number of exported functions #394

Merged
merged 11 commits into from
Jun 1, 2022
44 changes: 21 additions & 23 deletions R/get_quantile.R
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
#' @title Wrapper around quantile methods
#'
#' @description S3 method for extracting quantiles.
#' @description S3 method for extracting quantiles.
#' No default method is available at the moment.
#'
#'
#' @seealso \code{\link[survival]{quantile.survfit}}
#'
#'
#' @param x An object of class \code{survfit}
#' @param probs probabilities Default = c(0.25,0.50,0.75)
#' @inheritParams survival::quantile.survfit
#' @param ... other arguments passed on to the method
#'
#'
#' @examples
#'
#'
#' ## Kaplan-Meier estimates
#' survfit_object <- visR::estimate_KM(data = adtte, strata = c("TRTP"))
#'
#'
#' ## visR quantiles
#' visR::get_quantile(survfit_object)
#'
#'
#' ## survival quantiles
#' quantile(survfit_object)
#'
#'
#' @return A data frame with quantiles of the object
#'
#'
#' @rdname get_quantile
#'
#' @export

#'
get_quantile <- function(x, ...){
UseMethod("get_quantile", x)
}
}

#' @rdname get_quantile
#' @method get_quantile survfit
Expand All @@ -41,40 +39,40 @@ get_quantile.survfit <- function(x,
conf.int = TRUE,
tolerance = sqrt(.Machine$double.eps)
) {


# User input validation ---------------------------------------------------

if (conf.int == TRUE & !base::all(c("lower", "upper") %in% names(x)))
stop("Confidence limits were not part of original estimation.")

if (!base::all(is.numeric(probs) == TRUE) | (!base::all(probs < 1)))
stop("probs should be a numeric vector.")

if (!is.numeric(tolerance))
stop("tolerance should be numeric")

# Extract quantiles -------------------------------------------------------

q <- quantile( x
,probs = probs
,conf.int = conf.int
,tolerance = tolerance
,type = 3
)

qdf <- do.call(rbind.data.frame, q)

strata <- as.character(unlist(lapply(q, rownames)))
quantity <- unlist(lapply(strsplit(rownames(qdf), "\\.", fixed = FALSE), `[[`, 1))

final <- data.frame(
cbind(strata, quantity, qdf)
,row.names = NULL
,check.names = FALSE
)

final <- final[ order( final[, "strata"], final[, "quantity"] ), ]

return(final)
}
9 changes: 2 additions & 7 deletions R/get_risktable.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,13 @@
#' number of patients at risk per strata
#' @rdname get_risktable
#'
#' @export

get_risktable <- function(x, ...){
UseMethod("get_risktable")
}

#' @rdname get_risktable
#' @method get_risktable survfit
#' @export

#'
get_risktable.survfit <- function(
x
,times = NULL
Expand Down Expand Up @@ -225,7 +222,7 @@ get_risktable.survfit <- function(

#' @rdname get_risktable
#' @method get_risktable tidycuminc
#' @export
#'
get_risktable.tidycuminc <- function(x
,times = pretty(x$tidy$time, 10)
,statlist = "n.risk"
Expand Down Expand Up @@ -340,5 +337,3 @@ get_risktable.tidycuminc <- function(x

return(label[seq_along(statlist)])
}


7 changes: 2 additions & 5 deletions R/get_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
#'
#' @rdname get_summary
#'
#' @export
bailliem marked this conversation as resolved.
Show resolved Hide resolved

get_summary <- function(x, ...){
UseMethod("get_summary", x)
}

#' @examples
#' @examples
#'
#' survfit_object <- survival::survfit(data = adtte, survival::Surv(AVAL, 1-CNSR) ~ TRTP)
#' get_summary(survfit_object)
Expand All @@ -26,8 +24,7 @@ get_summary <- function(x, ...){
#'
#' @rdname get_summary
#' @method get_summary survfit
#' @export

#'
get_summary.survfit <- function(x,
statlist = c("strata", "records", "events", "median", "LCL", "UCL", "CI"),
...) {
Expand Down
6 changes: 2 additions & 4 deletions R/get_tableone.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#'
#' @note All columns in the table will be summarized. If only some columns shall be used, please select only those
#' variables prior to creating the summary table by using dplyr::select()

#'
#' @examples
#'
#' # Example using the ovarian data set
Expand Down Expand Up @@ -68,8 +68,6 @@
#'
#' @rdname get_tableone
#'
#' @export

get_tableone <- function(data, strata = NULL, overall=TRUE, summary_function = summarize_short){
UseMethod("get_tableone")
}
Expand All @@ -78,7 +76,7 @@ get_tableone <- function(data, strata = NULL, overall=TRUE, summary_function = s
#' @method get_tableone default
#' @return object of class tableone. That is a list of data specified summaries
#' for all input variables.
#' @export
#'
get_tableone.default <- function(data, strata = NULL, overall=TRUE, summary_function = summarize_short){

summary_FUN <- match.fun(summary_function)
Expand Down
5 changes: 0 additions & 5 deletions R/utils_pipe.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@

#' @title Find the "lhs" in the pipeline
#'
#' @description This function finds the left-hand sided symbol in a magrittr pipe and returns it as a character.
#'
#' @return Left-hand sided symbol as string in the magrittr pipe.
#'
#' @references \url{https://github.com/tidyverse/magrittr/issues/115#issuecomment-173894787}
#'
#' @export
#'
#' @examples
#' blah <- function(x) the_lhs()
#' adtte %>%
Expand Down
12 changes: 1 addition & 11 deletions R/utils_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
#'
#' @param x an object
#' @return A summarized version of the input.
#' @export
summarize_long <- function(x) UseMethod("summarize_long")


#' Create variable summary for factors
#'
#' @param x an object of class "factor"
#' @return Long list of summary statistics for the input factors.
#' @export
summarize_long.factor <- function(x){
x1 <- forcats::fct_explicit_na(x, na_level = "Missing")

Expand All @@ -29,7 +27,6 @@ summarize_long.factor <- function(x){
#'
#' @param x an object of class "integer"
#' @return Long list of summary statistics for the input.
#' @export
summarize_long.integer <- function(x){
summarize_long.numeric(x)
}
Expand All @@ -38,7 +35,6 @@ summarize_long.integer <- function(x){
#'
#' @param x an object of class "numeric"
#' @return Long list of summary statistics for the input.
#' @export
summarize_long.numeric <- function(x){
dat <- list(
mean = mean(x, na.rm = TRUE),
Expand All @@ -56,7 +52,6 @@ summarize_long.numeric <- function(x){
#'
#' @param x an object of any other class
#' @return List of counts for unique and missing values in `x`.
#' @export
summarize_long.default <- function(x){
dat <- list(
unique_values = length(unique(x)),
Expand All @@ -71,7 +66,6 @@ summarize_long.default <- function(x){
#'
#' @param x a vector to be summarized
#' @return A summarized less detailed version of the input.
#' @export
summarize_short <- function(x) UseMethod("summarize_short")

#' Create variable summary for factors
Expand All @@ -80,7 +74,6 @@ summarize_short <- function(x) UseMethod("summarize_short")
#'
#' @param x an object of class "factor"
#' @return Short list of summary statistics for the input factors.
#' @export
summarize_short.factor <- function(x){
x1 <- forcats::fct_explicit_na(x, na_level = "Missing")

Expand All @@ -101,7 +94,6 @@ summarize_short.factor <- function(x){
#'
#' @param x an object of class "numeric"
#' @return Short list of summary statistics for the input.
#' @export
summarize_short.numeric <- function(x){
dat <- list(
`Mean (SD)` = paste0(format(mean(x, na.rm = TRUE), digits = 3), " (", format(sd(x, na.rm = TRUE), digits = 3), ")"),
Expand All @@ -121,7 +113,6 @@ summarize_short.numeric <- function(x){
#'
#' @param x an object of class "integer"
#' @return Short list of summary statistics for the input.
#' @export
summarize_short.integer <- function(x){
summarize_short.numeric(x)
}
Expand All @@ -130,11 +121,10 @@ summarize_short.integer <- function(x){
#'
#' @param x an object of any other class
#' @return List of counts for unique and missing values in `x`.
#' @export
summarize_short.default <- function(x){
dat <- list(
`Unique values` = format(length(unique(x))),
`Missing (%)` = paste0(format(sum(is.na(x))), " (", format(100 * sum(is.na(x))/length(x), trim=TRUE), "%)")
)
list(dat)
}
}
3 changes: 0 additions & 3 deletions R/utils_visr.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
#' align = "none",
#' nrow=2)
#' }
#' @export
bailliem marked this conversation as resolved.
Show resolved Hide resolved


align_plots <- function(pltlist) {

if (missing(pltlist) | is.null(pltlist)) {
Expand Down