Skip to content

Commit

Permalink
export ggalign_lvls_set and ggalign_lvls_get
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Jan 10, 2025
1 parent 5896fc3 commit d54635f
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ export(ggalign_attr)
export(ggalign_attr_get)
export(ggalign_attr_set)
export(ggalign_lvls)
export(ggalign_lvls_get)
export(ggalign_lvls_set)
export(ggalign_stat)
export(ggcross)
export(ggfree)
Expand Down
21 changes: 19 additions & 2 deletions R/layout-.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,10 @@ ggalign_stat.AlignGg <- ggalign_stat.default
#' returned.
#' @param check A boolean indicating whether to check if the `field` exists. If
#' `TRUE`, an error will be raised if the specified `field` does not exist.
#' @return The specified data from the attached attribute or `NULL` if it is
#' unavailable.
#' @return
#' - `ggalign_attr`: The specified data from the attached attribute or `NULL` if
#' it is unavailable.
#' - `ggalign_lvls`: The attached levels.
#'
#' @export
ggalign_attr <- function(x, field = NULL, check = TRUE) {
Expand Down Expand Up @@ -237,11 +239,26 @@ ggalign_attr_remove <- function(x) ggalign_attr_set(x, NULL)
#' @rdname ggalign_attr
ggalign_lvls <- function(x) ggalign_lvls_get(x)

#' Set or Get the Attached Levels
#'
#' @description
#' - `ggalign_lvls_set`: Attaches levels to the input, enabling the restoration
#' of the `value` column when transformed from a matrix to a data frame.
#' - `ggalign_lvls_get`: Extracts previously attached levels during the
#' transformation process.
#'
#' @param x Input data for the layout.
#' @param lvls A character vector representing the attached levels.
#' @inherit ggalign_lvls details
#' @seealso [`ggalign_lvls()`]
#' @export
ggalign_lvls_set <- function(x, lvls) {
attr(x, ".__ggalign_levels__") <- lvls
x
}

#' @export
#' @rdname ggalign_lvls_set
ggalign_lvls_get <- function(x) attr(x, ".__ggalign_levels__", exact = TRUE)

ggalign_lvls_remove <- function(x) ggalign_lvls_set(x, NULL)
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ reference:
- fortify_matrix
- fortify_upset
- ggalign_attr_set
- ggalign_lvls_set
- order2

- title: Plot composer
Expand Down
7 changes: 5 additions & 2 deletions man/ggalign_attr.Rd

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

35 changes: 35 additions & 0 deletions man/ggalign_lvls_set.Rd

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

0 comments on commit d54635f

Please sign in to comment.