Skip to content

Commit a60c023

Browse files
Merge pull request #92 from tidymodels/RC0.1.0
Rc0.1.0
2 parents 521132e + ff75197 commit a60c023

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+463
-430
lines changed

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010
^\.github$
1111
^dev$
1212
^vignettes/articles$
13+
^cran-comments\.md$
14+
^CRAN-SUBMISSION$

DESCRIPTION

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
Package: tidyclust
22
Title: A Common API to Clustering
3-
Version: 0.0.0.9000
3+
Version: 0.1.0
44
Authors@R: c(
55
person("Emil", "Hvitfeldt", , "emilhhvitfeldt@gmail.com", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0002-0679-1945")),
77
person("Kelly", "Bodwin", , "kelly@bodwin.us", role = "aut"),
8-
person("RStudio", role = c("cph", "fnd"))
8+
person("Posit Software, PBC.", role = c("cph", "fnd"))
99
)
1010
Description: A common interface to specifying clustering models, in the
11-
same style as `parsnip`. Creates unified interface across different
11+
same style as 'parsnip'. Creates unified interface across different
1212
functions and computational engines.
1313
License: MIT + file LICENSE
1414
URL: https://github.com/tidymodels/tidyclust
@@ -45,8 +45,6 @@ Suggests:
4545
rmarkdown,
4646
testthat (>= 3.0.0),
4747
workflows (>= 1.1.2)
48-
VignetteBuilder:
49-
knitr
5048
Config/Needs/website: pkgdown, tidymodels, tidyverse, palmerpenguins,
5149
patchwork, ggforce
5250
Config/testthat/edition: 3

NAMESPACE

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,8 @@ S3method(tune_cluster,workflow)
4949
S3method(update,hier_clust)
5050
S3method(update,k_means)
5151
export("%>%")
52-
export(.convert_form_to_x_fit)
53-
export(.convert_form_to_x_new)
54-
export(.convert_x_to_form_fit)
55-
export(.convert_x_to_form_new)
5652
export(ClusterR_kmeans_fit)
5753
export(augment)
58-
export(check_empty_ellipse_tidyclust)
5954
export(cluster_metric_set)
6055
export(control_cluster)
6156
export(extract_centroids)

R/arguments.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ make_form_call <- function(object, env = NULL) {
6565
fit_call
6666
}
6767

68+
#' Change arguments of a cluster specification
69+
#'
70+
#' @inheritParams parsnip::set_args
71+
#' @return An updated `cluster_spec` object.
6872
#' @export
6973
set_args.cluster_spec <- function(object, ...) {
7074
the_dots <- enquos(...)
@@ -90,6 +94,10 @@ set_args.cluster_spec <- function(object, ...) {
9094
)
9195
}
9296

97+
#' Change mode of a cluster specification
98+
#'
99+
#' @inheritParams parsnip::set_mode
100+
#' @return An updated `cluster_spec` object.
93101
#' @export
94102
set_mode.cluster_spec <- function(object, mode) {
95103
cls <- class(object)[1]

R/augment.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#' @param new_data A data frame or matrix.
1010
#' @param ... Not currently used.
1111
#' @rdname augment
12+
#' @return A `tibble::tibble()` with containing `new_data` with columns added
13+
#' depending on the mode of the model.
1214
#' @examples
1315
#' kmeans_spec <- k_means(num_clusters = 5) %>%
1416
#' set_engine("stats")

R/cluster_spec.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
#' These functions are helpful when creating new packages that will register new
44
#' cluster specifications.
55
#'
6+
#' @return A `cluster_spec` object made to work with tidyclust.
7+
#'
68
#' @export
79
#' @keywords internal
8-
#' @rdname add_on_exports
910
new_cluster_spec <- function(cls, args, eng_args, mode, method, engine) {
1011
modelenv::check_spec_mode_engine_val(model = cls, mode = mode, eng = engine)
1112

R/convert_data.R

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#' @inheritParams fit.cluster_spec
3131
#' @rdname convert_helpers
3232
#' @keywords internal
33-
#' @export
3433
.convert_form_to_x_fit <- function(formula,
3534
data,
3635
...,
@@ -149,10 +148,8 @@ local_one_hot_contrasts <- function(frame = rlang::caller_env()) {
149148
#' @param weights A numeric vector containing the weights.
150149
#' @inheritParams fit.cluster_spec
151150
#' @inheritParams .convert_form_to_x_fit
152-
#'
153151
#' @rdname convert_helpers
154152
#' @keywords internal
155-
#' @export
156153
.convert_x_to_form_fit <- function(x,
157154
weights = NULL,
158155
remove_intercept = TRUE) {
@@ -210,7 +207,6 @@ make_formula <- function(x, short = TRUE) {
210207
#' @inheritParams predict.cluster_fit
211208
#' @rdname convert_helpers
212209
#' @keywords internal
213-
#' @export
214210
.convert_form_to_x_new <- function(object,
215211
new_data,
216212
na.action = stats::na.pass,
@@ -262,7 +258,6 @@ make_formula <- function(x, short = TRUE) {
262258

263259
#' @rdname convert_helpers
264260
#' @keywords internal
265-
#' @export
266261
.convert_x_to_form_new <- function(object, new_data) {
267262
new_data <- new_data[, object$x_var, drop = FALSE]
268263
if (!is.data.frame(new_data)) {

R/engines.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#' Change engine of a cluster specification
2+
#'
3+
#' @inheritParams parsnip::set_engine
4+
#' @return An updated `cluster_spec` object.
15
#' @export
26
set_engine.cluster_spec <- function(object, engine, ...) {
37
mod_type <- class(object)[1]

R/extract.R

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,50 @@
1+
#' Extract elements of a tidyclust model object
2+
#'
3+
#' @description
4+
#' These functions extract various elements from a clustering object. If they do
5+
#' not exist yet, an error is thrown.
6+
#'
7+
#' - `extract_fit_engine()` returns the engine specific fit embedded within
8+
#' a tidyclust model fit. For example, when using [tidyclust::k_means()]
9+
#' with the `"lm"` engine, this returns the underlying `kmeans` object.
10+
#'
11+
#' - `extract_parameter_set_dials()` returns a set of dials parameter objects.
12+
#'
13+
#' @param x A `cluster_fit` object or a `cluster_spec` object.
14+
#' @param ... Not currently used.
15+
#' @details
16+
#' Extracting the underlying engine fit can be helpful for describing the
17+
#' model (via `print()`, `summary()`, `plot()`, etc.) or for variable
18+
#' importance/explainers.
19+
#'
20+
#' However, users should not invoke the `predict()` method on an extracted
21+
#' model. There may be preprocessing operations that `tidyclust` has executed
22+
#' on the data prior to giving it to the model. Bypassing these can lead to
23+
#' errors or silently generating incorrect predictions.
24+
#'
25+
#' **Good**:
26+
#' ```r
27+
#' tidyclust_fit %>% predict(new_data)
28+
#' ```
29+
#'
30+
#' **Bad**:
31+
#' ```r
32+
#' tidyclust_fit %>% extract_fit_engine() %>% predict(new_data)
33+
#' ```
34+
#' @return
35+
#' The extracted value from the tidyclust object, `x`, as described in the
36+
#' description section.
37+
#'
38+
#' @name extract-tidyclust
39+
#' @examples
40+
#' kmeans_spec <- k_means(num_clusters = 2)
41+
#' kmeans_fit <- fit(kmeans_spec, ~ ., data = mtcars)
42+
#'
43+
#' extract_fit_engine(kmeans_fit)
44+
NULL
45+
46+
47+
#' @rdname extract-tidyclust
148
#' @export
249
extract_fit_engine.cluster_fit <- function (x, ...) {
350
if (any(names(x) == "fit")) {

R/extract_assignment.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#' @param object An cluster_spec object.
44
#' @param ... Other arguments passed to methods.
55
#'
6+
#' @return A `tibble::tibble()` with 1 column `.cluster`.
7+
#'
68
#' @examples
79
#' kmeans_spec <- k_means(num_clusters = 5) %>%
810
#' set_engine("stats")

0 commit comments

Comments
 (0)