Skip to content

Commit

Permalink
Rename as_features() to augment()
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed Aug 5, 2024
1 parent 676f0ee commit a769fb7
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 88 deletions.
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ exportMethods("set_totals<-")
exportMethods(aggregate)
exportMethods(as_amounts)
exportMethods(as_composition)
exportMethods(as_features)
exportMethods(as_graph)
exportMethods(augment)
exportMethods(barplot)
exportMethods(closure)
exportMethods(condense)
Expand Down Expand Up @@ -120,4 +120,5 @@ importFrom(utils,tail)
importMethodsFrom(arkhe,describe)
importMethodsFrom(arkhe,replace_NA)
importMethodsFrom(arkhe,replace_zero)
importMethodsFrom(dimensio,augment)
importMethodsFrom(dimensio,pca)
17 changes: 8 additions & 9 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ setGeneric("mahalanobis", package = "stats")
#' @importMethodsFrom arkhe describe
#' @importMethodsFrom arkhe replace_NA
#' @importMethodsFrom arkhe replace_zero
#' @importMethodsFrom dimensio augment
#' @importMethodsFrom dimensio pca
NULL

Expand Down Expand Up @@ -54,22 +55,20 @@ setGeneric(
valueClass = "matrix"
)

#' Coerce to Features
#' Augment Data with Extra Columns
#'
#' Converts an object to a collection of features.
#' @param from A [`CompositionMatrix-class`] object.
#' Adds columns from the original data.
#' @param x A [`CompositionMatrix-class`] or [`LogRatio-class`] object.
#' @param ... Currently not used.
#' @return
#' A [`data.frame`].
#' @example inst/examples/ex-coerce.R
#' @example inst/examples/ex-augment.R
#' @author N. Frerebeau
#' @docType methods
#' @family compositional data tools
#' @aliases as_features-method
setGeneric(
name = "as_features",
def = function(from, ...) standardGeneric("as_features")
)
#' @name augment
#' @rdname augment
NULL

#' Data Description
#'
Expand Down
36 changes: 18 additions & 18 deletions R/coerce.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ setMethod(
}
)

# To Amounts ===================================================================
# To amounts ===================================================================
#' @export
#' @rdname as_amounts
#' @aliases as_amounts,CompositionMatrix-method
Expand All @@ -87,33 +87,33 @@ setMethod(
}
)

# To Features ==================================================================
# To features ==================================================================
#' @export
#' @rdname as_features
#' @aliases as_features,CompositionMatrix-method
#' @rdname augment
#' @aliases augment,CompositionMatrix-method
setMethod(
f = "as_features",
signature = c(from = "CompositionMatrix"),
definition = function(from) {
if (has_extra(from)) {
data.frame(get_extra(from), from)
f = "augment",
signature = c(x = "CompositionMatrix"),
definition = function(x, ...) {
if (has_extra(x)) {
data.frame(get_extra(x), x)
} else {
as.data.frame(from)
as.data.frame(x)
}
}
)

#' @export
#' @rdname as_features
#' @aliases as_features,LogRatio-method
#' @rdname augment
#' @aliases augment,LogRatio-method
setMethod(
f = "as_features",
signature = c(from = "LogRatio"),
definition = function(from) {
if (has_extra(from)) {
data.frame(get_extra(from), from)
f = "augment",
signature = c(x = "LogRatio"),
definition = function(x, ...) {
if (has_extra(x)) {
data.frame(get_extra(x), x)
} else {
as.data.frame(from)
as.data.frame(x)
}
}
)
Expand Down
11 changes: 11 additions & 0 deletions inst/examples/ex-augment.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Data from Aitchison 1986
data("arctic")

## Coerce to compositional data
coda <- as_composition(arctic, parts = 1:3)

## Isometric log-ratio
ilr <- transform_ilr(coda)

## Add extra column
augment(ilr)
2 changes: 1 addition & 1 deletion inst/examples/ex-mutators.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ head(slides)

## Coerce to compositional data
coda <- as_composition(slides)
head(as_features(coda))
head(augment(coda))
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions inst/tinytest/test_coerce.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Data with groups =============================================================
data("slides")
coda <- as_composition(slides)
expect_equal_to_reference(as_features(coda), file = "_snaps/features.rds")
expect_equal_to_reference(augment(coda), file = "_snaps/augment_coda.rds")

clr <- transform_clr(coda, weights = FALSE)
expect_equal_to_reference(clr, file = "_snaps/features_clr.rds")
expect_equal_to_reference(clr, file = "_snaps/augment_clr.rds")

# Back transform to count ======================================================
data("hongite")
Expand Down
1 change: 0 additions & 1 deletion inst/tinytest/test_outliers.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ coda <- as_composition(hongite)
# Detect outliers ==============================================================
out <- outliers(coda)
# expect_equal_to_reference(out, file = "_snaps/outliers.rds")
# expect_equal_to_reference(as_features(out), file = "_snaps/features_outliers.rds")

# Plot =========================================================================
if (at_home()) {
Expand Down
2 changes: 1 addition & 1 deletion man/as_amounts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/as_composition.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 0 additions & 53 deletions man/as_features.Rd

This file was deleted.

46 changes: 46 additions & 0 deletions man/augment.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/groups.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a769fb7

Please sign in to comment.