Skip to content

Commit f58b1e3

Browse files
authored
Merge pull request #319 from stemangiola/drop_env_for_enquo
use a function to drop env
2 parents d310912 + c7b4eae commit f58b1e3

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

NAMESPACE

+2
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,15 @@ importFrom(rlang,enquo)
155155
importFrom(rlang,enquos)
156156
importFrom(rlang,flatten_if)
157157
importFrom(rlang,inform)
158+
importFrom(rlang,is_quosure)
158159
importFrom(rlang,is_spliced)
159160
importFrom(rlang,quo)
160161
importFrom(rlang,quo_is_missing)
161162
importFrom(rlang,quo_is_null)
162163
importFrom(rlang,quo_is_symbol)
163164
importFrom(rlang,quo_is_symbolic)
164165
importFrom(rlang,quo_name)
166+
importFrom(rlang,quo_set_env)
165167
importFrom(rlang,quo_squash)
166168
importFrom(rlang,set_names)
167169
importFrom(scales,extended_breaks)

R/methods.R

+8-8
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,10 @@ setGeneric("scale_abundance", function(.data,
477477

478478
# Attach column internals
479479
add_tt_columns(
480-
!!.sample,
481-
!!.transcript,
482-
!!.abundance,
483-
!!(function(x, v) enquo(v))(x,!!value_scaled)
480+
!!(.sample |> drop_enquo_env()),
481+
!!(.transcript |> drop_enquo_env()),
482+
!!(.abundance |> drop_enquo_env()),
483+
!!(((function(x, v) enquo(v))(x,!!value_scaled)) |> drop_enquo_env())
484484
)
485485

486486

@@ -698,10 +698,10 @@ setGeneric("quantile_normalise_abundance", function(.data,
698698

699699
# Attach column internals
700700
add_tt_columns(
701-
!!.sample,
702-
!!.transcript,
703-
!!.abundance,
704-
!!(function(x, v) enquo(v))(x,!!value_scaled)
701+
!!(.sample |> drop_enquo_env()),
702+
!!(.transcript |> drop_enquo_env()),
703+
!!(.abundance |> drop_enquo_env()),
704+
!!(((function(x, v) enquo(v))(x,!!value_scaled)) |> drop_enquo_env())
705705
)
706706

707707

R/methods_SE.R

+3-4
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ setMethod("tidybulk", "RangedSummarizedExperiment", .tidybulk_se)
196196
memorise_methods_used(c("edger", "tmm")) %>%
197197

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

201201
}
202202

@@ -321,7 +321,7 @@ setMethod("scale_abundance",
321321
memorise_methods_used(c("quantile")) %>%
322322

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

326326
}
327327

@@ -953,8 +953,7 @@ setMethod("remove_redundancy",
953953
memorise_methods_used("sva") %>%
954954

955955
# Attach column internals
956-
add_tt_columns(.abundance_adjusted = !!(function(x, v)
957-
enquo(v))(x, !!as.symbol(value_adjusted)))
956+
add_tt_columns(.abundance_adjusted = !!(((function(x, v) enquo(v))(x,!!as.symbol(value_adjusted))) |> drop_enquo_env()) )
958957

959958
}
960959

R/utilities.R

+28
Original file line numberDiff line numberDiff line change
@@ -1514,3 +1514,31 @@ check_and_install_packages <- function(packages) {
15141514
)
15151515
}
15161516
}
1517+
1518+
#' Drop Environment from a Quosure
1519+
#'
1520+
#' Takes a quosure and resets its environment to `emptyenv()` without altering
1521+
#' its expression.
1522+
#'
1523+
#' @param q A quosure object to have its environment stripped.
1524+
#' @return A quosure with the same expression but environment set to `emptyenv()`.
1525+
#'
1526+
#' @importFrom rlang is_quosure
1527+
#' @importFrom rlang quo_set_env
1528+
#'
1529+
#' @examples
1530+
#' library(rlang)
1531+
#'
1532+
#' q <- quo(x + y)
1533+
#' environment(q)
1534+
#'
1535+
#' q_stripped <- drop_enquo_env(q)
1536+
#' identical(quo_get_env(q_stripped), emptyenv()) # TRUE
1537+
#'
1538+
#' @noRd
1539+
drop_enquo_env <- function(q) {
1540+
if (!rlang::is_quosure(q)) {
1541+
stop("`q` must be a quosure.")
1542+
}
1543+
rlang::quo_set_env(q, emptyenv())
1544+
}

0 commit comments

Comments
 (0)