From df779e2048192abbe65f585600b78c28580d31fb Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Wed, 20 Sep 2023 09:01:57 -0400 Subject: [PATCH] estimates(): first attempt --- R/estimates.R | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 R/estimates.R diff --git a/R/estimates.R b/R/estimates.R new file mode 100644 index 000000000..ead9eb4ae --- /dev/null +++ b/R/estimates.R @@ -0,0 +1,54 @@ +estimates_dictionary_build <- function() { +text <- +'Model,Description,Package,Function +lm,Linear Model, stats,lm +logit,Logistic Regression,stats,glm +probit,Probit Regression,stats,glm +ologit,Ordered Logistic Regression,MASS,polr +oprobit,Ordered Probit Regression,MASS,polr +multinom,Multinomial Log-Linear,nnet,multinom' +out <- utils::read.csv( + text = text, + colClasses = c("character", "character", "character", "character")) +colnames(out) <- gsub("\\.$", "", colnames(out)) +for (i in 1:4) { + out[[i]] <- trimws(out[[i]]) +} +class(out) <- c("estimates_dictionary", "data.frame") +return(out) +} + + +#' estimates dictionary +#' +#' @noRd +estimates_dictionary <- estimates_dictionary_build() + + +print.estimates_dictionary <- function(x, ...) { + flag <- insight::check_if_installed("knitr", quietly = TRUE) + if (isTRUE(flag)) { + print(knitr::kable(x)) + } else { + print(x) + } +} + + +estimates <- function(formula, data, model, ...) { + if (missing(model)) { + return(estimates_dictionary) + } else { + checkmate::assert_choice(model, estimates_dictionary$Model) + } + if (missing(formula)) { + fun <- subset(estimates_dictionary, Model == model) + fun <- sprintf("%s::%s", fun$Package, fun$Function) + args <- names(as.list(args(eval(substitute(fun))))) + msg <- pi + insight::format_error(msg) + + if (missing(data) || !isTRUE(checkmate::check_data_frame(data, null.ok = FALSE))) { + insight::format_error("blah blah") + } +}