Skip to content

Commit ba1c867

Browse files
authored
export the format_*() functions (#740)
1 parent 6820609 commit ba1c867

File tree

5 files changed

+72
-3
lines changed

5 files changed

+72
-3
lines changed

NAMESPACE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,13 @@ export(fit.model_spec)
198198
export(fit_control)
199199
export(fit_xy)
200200
export(fit_xy.model_spec)
201+
export(format_class)
202+
export(format_classprobs)
203+
export(format_hazard)
204+
export(format_linear_pred)
205+
export(format_num)
206+
export(format_survival)
207+
export(format_time)
201208
export(gen_additive_mod)
202209
export(get_dependency)
203210
export(get_encoding)

R/predict.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,17 @@ check_pred_type <- function(object, type, ...) {
208208
type
209209
}
210210

211+
#' Internal functions that format predictions
212+
#'
213+
#' These are used to ensure that we have appropriate column names inside of
214+
#' tibbles.
215+
#'
216+
#' @param x A data frame or vector (depending on the context and function).
217+
#' @return A tibble
218+
#' @keywords internal
219+
#' @name format-internals
220+
#' @export
221+
211222
format_num <- function(x) {
212223
if (inherits(x, "tbl_spark"))
213224
return(x)
@@ -224,13 +235,17 @@ format_num <- function(x) {
224235
x
225236
}
226237

238+
#' @rdname format-internals
239+
#' @export
227240
format_class <- function(x) {
228241
if (inherits(x, "tbl_spark"))
229242
return(x)
230243

231244
tibble(.pred_class = unname(x))
232245
}
233246

247+
#' @rdname format-internals
248+
#' @export
234249
format_classprobs <- function(x) {
235250
if (!any(grepl("^\\.pred_", names(x)))) {
236251
names(x) <- paste0(".pred_", names(x))
@@ -240,6 +255,8 @@ format_classprobs <- function(x) {
240255
x
241256
}
242257

258+
#' @rdname format-internals
259+
#' @export
243260
format_time <- function(x) {
244261
if (isTRUE(ncol(x) > 1) | is.data.frame(x)) {
245262
x <- as_tibble(x, .name_repair = "minimal")
@@ -253,6 +270,8 @@ format_time <- function(x) {
253270
x
254271
}
255272

273+
#' @rdname format-internals
274+
#' @export
256275
format_survival <- function(x) {
257276
if (isTRUE(ncol(x) > 1) | is.data.frame(x)) {
258277
x <- as_tibble(x, .name_repair = "minimal")
@@ -264,6 +283,8 @@ format_survival <- function(x) {
264283
x
265284
}
266285

286+
#' @rdname format-internals
287+
#' @export
267288
format_linear_pred <- function(x) {
268289
if (inherits(x, "tbl_spark"))
269290
return(x)
@@ -278,6 +299,8 @@ format_linear_pred <- function(x) {
278299
x
279300
}
280301

302+
#' @rdname format-internals
303+
#' @export
281304
format_hazard <- function(x) {
282305
if (isTRUE(ncol(x) > 1) | is.data.frame(x)) {
283306
x <- as_tibble(x, .name_repair = "minimal")

man/details_naive_Bayes_klaR.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/details_naive_Bayes_naivebayes.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/format-internals.Rd

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)