Skip to content

Commit

Permalink
Store extra variables as a list
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed May 17, 2024
1 parent a67df51 commit ff9cb1f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions R/AllClasses.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#' @slot singular_values A [`numeric`] vector giving the singular values.
#' @slot rows A [`MultivariateResults-class`] object.
#' @slot columns A [`MultivariateResults-class`] object.
#' @slot extra A [`matrix`] of extra variables.
#' @slot extra A [`list`] of extra variables.
#' @section Subset:
#' In the code snippets below, `x` is a `MultivariateAnalysis` object.
#' \describe{
Expand All @@ -70,7 +70,7 @@
singular_values = "numeric",
rows = "MultivariateResults",
columns = "MultivariateResults",
extra = "matrix"
extra = "list"
),
contains = "VIRTUAL"
)
Expand Down
2 changes: 1 addition & 1 deletion R/mca.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ setMethod(
sup_row = sup_row, sup_col = clean$sup)

## Add supplementary quantitative variables
if (!is.null(sup_quanti)) set_extra(results) <- as.matrix(clean$extra)
if (!is.null(clean$extra)) set_extra(results) <- clean$extra

results
}
Expand Down
6 changes: 5 additions & 1 deletion R/mutators.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ has_extra <- function(x) {
NROW(extra) > 0 && NCOL(extra) > 0
}
`set_extra<-` <- function(x, value) {
value <- value[get_order(x, margin = 1), , drop = FALSE]
value <- lapply(
X = value,
FUN = function(val, i) { val[i] },
i = get_order(x, margin = 1)
)
x@extra <- value
methods::validObject(x)
x
Expand Down
2 changes: 1 addition & 1 deletion R/pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ setMethod(
)

## Add supplementary quantitative variables
if (!is.null(sup_quali)) set_extra(results) <- as.matrix(clean$extra)
if (!is.null(clean$extra)) set_extra(results) <- clean$extra

results
}
Expand Down
2 changes: 1 addition & 1 deletion man/MultivariateAnalysis.Rd

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

0 comments on commit ff9cb1f

Please sign in to comment.