Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use a function to drop env #319

Merged
merged 1 commit into from
Dec 13, 2024
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 NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,15 @@ importFrom(rlang,enquo)
importFrom(rlang,enquos)
importFrom(rlang,flatten_if)
importFrom(rlang,inform)
importFrom(rlang,is_quosure)
importFrom(rlang,is_spliced)
importFrom(rlang,quo)
importFrom(rlang,quo_is_missing)
importFrom(rlang,quo_is_null)
importFrom(rlang,quo_is_symbol)
importFrom(rlang,quo_is_symbolic)
importFrom(rlang,quo_name)
importFrom(rlang,quo_set_env)
importFrom(rlang,quo_squash)
importFrom(rlang,set_names)
importFrom(scales,extended_breaks)
Expand Down
16 changes: 8 additions & 8 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,10 @@ setGeneric("scale_abundance", function(.data,

# Attach column internals
add_tt_columns(
!!.sample,
!!.transcript,
!!.abundance,
!!(function(x, v) enquo(v))(x,!!value_scaled)
!!(.sample |> drop_enquo_env()),
!!(.transcript |> drop_enquo_env()),
!!(.abundance |> drop_enquo_env()),
!!(((function(x, v) enquo(v))(x,!!value_scaled)) |> drop_enquo_env())
)


Expand Down Expand Up @@ -698,10 +698,10 @@ setGeneric("quantile_normalise_abundance", function(.data,

# Attach column internals
add_tt_columns(
!!.sample,
!!.transcript,
!!.abundance,
!!(function(x, v) enquo(v))(x,!!value_scaled)
!!(.sample |> drop_enquo_env()),
!!(.transcript |> drop_enquo_env()),
!!(.abundance |> drop_enquo_env()),
!!(((function(x, v) enquo(v))(x,!!value_scaled)) |> drop_enquo_env())
)


Expand Down
7 changes: 3 additions & 4 deletions R/methods_SE.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ setMethod("tidybulk", "RangedSummarizedExperiment", .tidybulk_se)
memorise_methods_used(c("edger", "tmm")) %>%

# Attach column internals
add_tt_columns(.abundance_scaled = !!(function(x, v) enquo(v))(x,!!as.symbol(value_scaled)))
add_tt_columns(.abundance_scaled = !!(((function(x, v) enquo(v))(x,!!as.symbol(value_scaled))) |> drop_enquo_env()) )

}

Expand Down Expand Up @@ -321,7 +321,7 @@ setMethod("scale_abundance",
memorise_methods_used(c("quantile")) %>%

# Attach column internals
add_tt_columns(.abundance_scaled = !!(function(x, v) enquo(v))(x,!!as.symbol(value_scaled)))
add_tt_columns(.abundance_scaled = !!(((function(x, v) enquo(v))(x,!!as.symbol(value_scaled))) |> drop_enquo_env()) )

}

Expand Down Expand Up @@ -953,8 +953,7 @@ setMethod("remove_redundancy",
memorise_methods_used("sva") %>%

# Attach column internals
add_tt_columns(.abundance_adjusted = !!(function(x, v)
enquo(v))(x, !!as.symbol(value_adjusted)))
add_tt_columns(.abundance_adjusted = !!(((function(x, v) enquo(v))(x,!!as.symbol(value_adjusted))) |> drop_enquo_env()) )

}

Expand Down
28 changes: 28 additions & 0 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -1514,3 +1514,31 @@ check_and_install_packages <- function(packages) {
)
}
}

#' Drop Environment from a Quosure
#'
#' Takes a quosure and resets its environment to `emptyenv()` without altering
#' its expression.
#'
#' @param q A quosure object to have its environment stripped.
#' @return A quosure with the same expression but environment set to `emptyenv()`.
#'
#' @importFrom rlang is_quosure
#' @importFrom rlang quo_set_env
#'
#' @examples
#' library(rlang)
#'
#' q <- quo(x + y)
#' environment(q)
#'
#' q_stripped <- drop_enquo_env(q)
#' identical(quo_get_env(q_stripped), emptyenv()) # TRUE
#'
#' @noRd
drop_enquo_env <- function(q) {
if (!rlang::is_quosure(q)) {
stop("`q` must be a quosure.")
}
rlang::quo_set_env(q, emptyenv())
}
Loading