Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
^_pkgdown\.yml$
^docs$
^pkgdown$
^[.]?air[.]toml$
^\.vscode$
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
inst/doc
docs
pkgdown

/.quarto/
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"Posit.air-vscode"
]
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"[r]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "Posit.air-vscode"
},
"[quarto]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "quarto.quarto"
}
}
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: scimo
Title: Extra Recipes Steps for Dealing with Omics Data
Version: 0.0.2
Version: 0.0.3
Authors@R: c(
person("Antoine", "BICHAT", , "antoine.bichat@proton.me", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-6599-7081")),
Expand All @@ -17,7 +17,7 @@ URL: https://github.com/abichat/scimo
BugReports: https://github.com/abichat/scimo/issues
Depends:
R (>= 2.10),
recipes
recipes (>= 1.1)
Imports:
dplyr,
generics,
Expand All @@ -37,4 +37,4 @@ Config/testthat/edition: 3
Encoding: UTF-8
LazyData: false
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
7 changes: 6 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# scimo 0.0.3

* Add a dependency on **recipes** >= 1.1 to avoid stack overflow errors with long formulas, as this issue has been resolved in this version (#2).

* Small improvements in documentation (#6, CRAN notes).

# scimo 0.0.2

* New function `step_taxonomy()`.

* Replace superseded `juice()` with `bake(new_data = NULL)` to align with current practices (#1).


# scimo 0.0.1

* First release of **scimo**.
18 changes: 12 additions & 6 deletions R/aggregate.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
aggregate_var <- function(data, list_agg, fun_agg,
prefix = "agg_",
keep_original_cols = FALSE) {

aggregate_var <- function(
data,
list_agg,
fun_agg,
prefix = "agg_",
keep_original_cols = FALSE
) {
list_agg <- fill_name(list_agg, prefix)

for (i in seq_along(list_agg)) {
data[[names(list_agg[i])]] <- apply(data[, list_agg[[i]]],
MARGIN = 1, FUN = fun_agg)
data[[names(list_agg[i])]] <- apply(
data[, list_agg[[i]]],
MARGIN = 1,
FUN = fun_agg
)
}

if (!keep_original_cols) {
Expand Down
124 changes: 80 additions & 44 deletions R/aggregate_hclust.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @param recipe A recipe object. The step will be added to the sequence of
#' operations for this recipe.
#' @param ... One or more selector functions to choose variables
#' for this step. See [selections()] for more details.
#' for this step. See [recipes::selections()] for more details.
#' @param role For model terms created by this step, what analysis role should
#' they be assigned? By default, the new columns created by this step from
#' the original variables will be used as `predictors` in a model.
Expand All @@ -23,8 +23,8 @@
#' @param keep_original_cols A logical to keep the original variables in
#' the output. Defaults to `FALSE`.
#' @param skip A logical. Should the step be skipped when the
#' recipe is baked by [bake()]? While all operations are baked
#' when [prep()] is run, some operations may not be able to be
#' recipe is baked by [recipes::bake()]? While all operations are baked
#' when [recipes::prep()] is run, some operations may not be able to be
#' conducted on new data (e.g. processing the outcome variable(s)).
#' Care should be taken when using `skip = TRUE` as it may affect
#' the computations for subsequent operations.
Expand All @@ -50,18 +50,21 @@
#' rec
#' tidy(rec, 1)
#' bake(rec, new_data = NULL)
step_aggregate_hclust <- function(recipe, ..., role = "predictor",
trained = FALSE,
n_clusters,
fun_agg,
dist_metric = "euclidean",
linkage_method = "complete",
res = NULL,
prefix = "cl_",
keep_original_cols = FALSE,
skip = FALSE,
id = rand_id("aggregate_hclust")) {

step_aggregate_hclust <- function(
recipe,
...,
role = "predictor",
trained = FALSE,
n_clusters,
fun_agg,
dist_metric = "euclidean",
linkage_method = "complete",
res = NULL,
prefix = "cl_",
keep_original_cols = FALSE,
skip = FALSE,
id = rand_id("aggregate_hclust")
) {
add_step(
recipe,
step_aggregate_hclust_new(
Expand All @@ -82,25 +85,35 @@ step_aggregate_hclust <- function(recipe, ..., role = "predictor",
}

#' @importFrom recipes step
step_aggregate_hclust_new <- function(terms, role, trained,
n_clusters, fun_agg,
dist_metric, linkage_method,
res, prefix, keep_original_cols,
skip, id) {

step(subclass = "aggregate_hclust",
terms = terms,
role = role,
trained = trained,
n_clusters = n_clusters,
fun_agg = fun_agg,
dist_metric = dist_metric,
linkage_method = linkage_method,
res = res,
prefix = prefix,
keep_original_cols = keep_original_cols,
skip = skip,
id = id)
step_aggregate_hclust_new <- function(
terms,
role,
trained,
n_clusters,
fun_agg,
dist_metric,
linkage_method,
res,
prefix,
keep_original_cols,
skip,
id
) {
step(
subclass = "aggregate_hclust",
terms = terms,
role = role,
trained = trained,
n_clusters = n_clusters,
fun_agg = fun_agg,
dist_metric = dist_metric,
linkage_method = linkage_method,
res = res,
prefix = prefix,
keep_original_cols = keep_original_cols,
skip = skip,
id = id
)
}

#' @export
Expand All @@ -112,12 +125,32 @@ step_aggregate_hclust_new <- function(terms, role, trained,
prep.step_aggregate_hclust <- function(x, training, info = NULL, ...) {
col_names <- recipes_eval_select(x$terms, training, info)
check_type(training[, col_names], quant = TRUE)
check_in(x$dist_metric, name_x = "dist_metric",
values = c("euclidean", "maximum", "manhattan",
"canberra", "binary", "minkowski"))
check_in(x$linkage_method, name_x = "linkage_method",
values = c("ward.D", "ward.D2", "single", "complete",
"average", "mcquitty", "median", "centroid"))
check_in(
x$dist_metric,
name_x = "dist_metric",
values = c(
"euclidean",
"maximum",
"manhattan",
"canberra",
"binary",
"minkowski"
)
)
check_in(
x$linkage_method,
name_x = "linkage_method",
values = c(
"ward.D",
"ward.D2",
"single",
"complete",
"average",
"mcquitty",
"median",
"centroid"
)
)

ct <-
training[, col_names] %>%
Expand All @@ -132,7 +165,6 @@ prep.step_aggregate_hclust <- function(x, training, info = NULL, ...) {
enframe(name = "terms", value = "aggregate") %>%
mutate(aggregate = paste0(x$prefix, .data$aggregate))


step_aggregate_hclust_new(
terms = x$terms,
role = x$role,
Expand All @@ -158,9 +190,13 @@ bake.step_aggregate_hclust <- function(object, new_data, ...) {

list_agg_hc <- split(object$res$terms, object$res$aggregate)

aggregate_var(new_data, list_agg = list_agg_hc, fun_agg = object$fun_agg,
prefix = object$prefix,
keep_original_cols = object$keep_original_cols)
aggregate_var(
new_data,
list_agg = list_agg_hc,
fun_agg = object$fun_agg,
prefix = object$prefix,
keep_original_cols = object$keep_original_cols
)
}

#' @export
Expand Down
Loading
Loading