Skip to content

Commit

Permalink
removed conflicts package startup messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jtlandis committed Oct 28, 2024
1 parent 2c7a7ed commit b6287e3
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 91 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: plyxp
Title: Data masks for SummarizedExperiment enabling dplyr-like manipulation
Version: 0.99.23
Version: 0.99.24
Authors@R: c(
person("Justin", "Landis", email = "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-5501-4934")),
Expand Down
7 changes: 6 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@

## plyxp 0.99.24

* Since `plyxp` does not have a conflict with `tidySummarizedExperiment` anymore,
we have removed package startup messages warning of potential conflicts.

## plyxp 0.99.21

* Fixed documentation of `?plyxp::mutate` and other dplyr functions reexported
by `plyxp`.
* `PlySummarizedExperiment` should be able to hold any `SummarizedExperiment`
* `PlySummarizedExperiment` should be able to hold any `SummarizedExperiment`
object

## plyxp 0.99.20
Expand Down
178 changes: 89 additions & 89 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,101 +1,101 @@
conflict_info <- c(
"Note that these packages are exclusive and present different APIs ",
"for working with {.cls SummarizedExperiment} objects. As such conflicts ",
"and unexpected behaviors may arise!"
)
# conflict_info <- c(
# "Note that these packages are exclusive and present different APIs ",
# "for working with {.cls SummarizedExperiment} objects. As such conflicts ",
# "and unexpected behaviors may arise!"
# )

# rule <- function (pad = "-", gap = 2L) {
# paste0(rep(pad, getOption("width") - gap), collapse = "")
# }

# tidySE_opt <- list(quote(tidySummarizedExperiment), "tidySummarizedExperiment")

# attaching_tidySE <- function(expr) {
# if (is_call(expr, name = "library")) {
# call <- match.call(library, call = expr)
# out <- tidySE_opt |>
# vapply(identical, y = call$package, logical(1)) |>
# any()
# return(out)
# }
# FALSE

# }

rule <- function (pad = "-", gap = 2L) {
paste0(rep(pad, getOption("width") - gap), collapse = "")
}

tidySE_opt <- list(quote(tidySummarizedExperiment), "tidySummarizedExperiment")

attaching_tidySE <- function(expr) {
if (is_call(expr, name = "library")) {
call <- match.call(library, call = expr)
out <- tidySE_opt |>
vapply(identical, y = call$package, logical(1)) |>
any()
return(out)
}
FALSE

}
# you_have_loaded <- function(pkg1, pkg2, .class = NULL) {
# if (!is.null(.class)) {
# local_options(cli.message_class = .class)
# }
# withRestarts({
# cli::cli_rule()
# cli::cli_alert_warning(
# "you have loaded {.pkg {pkg1}} after {.pkg {pkg2}}\n"
# )
# cli::cli_text("")
# cli::cli_text(conflict_info)
# cli::cli_text("")
# },
# muffleMessage = function() NULL)

# }

# # a package can either be loaded, or completely attached. R only informs
# # of conflicts when the package is loaded, and when attached these can be
# # overwritten silently

you_have_loaded <- function(pkg1, pkg2, .class = NULL) {
if (!is.null(.class)) {
local_options(cli.message_class = .class)
}
withRestarts({
cli::cli_rule()
cli::cli_alert_warning(
"you have loaded {.pkg {pkg1}} after {.pkg {pkg2}}\n"
)
cli::cli_text("")
cli::cli_text(conflict_info)
cli::cli_text("")
},
muffleMessage = function() NULL)

}
# .onAttach <- function(libname, pkgname) {
# # check if `tidySummarizedExperiment` is already loaded
# conflict <- grep("tidySummarizedExperiment", search(), value = TRUE)
# if (length(conflict)) {
# you_have_loaded("plyxp","tidySummarizedExperiment",
# .class = c("packageStartupMessage", "message"))
# }
# # set hook for if `tidySummarizedExperiment` gets attached latter
# setHook(
# packageEvent(pkgname = "tidySummarizedExperiment",
# event = "attach"),
# function(...) {
# you_have_loaded("tidySummarizedExperiment","plyxp",
# .class = c("packageStartupMessage", "message"))
# }

# a package can either be loaded, or completely attached. R only informs
# of conflicts when the package is loaded, and when attached these can be
# overwritten silently
# )
# # hook for when tidySummarizedExperiment:: is used after plyxp is attached
# setHook(
# packageEvent(pkgname = "tidySummarizedExperiment",
# event = "onLoad"),
# function(...) {
# calls <- sys.calls()
# called_via_library <- vapply(calls, attaching_tidySE, logical(1))
# if (!any(called_via_library)) {
# # if this callback was not executed via library(tidySummarizedExperiment)
# # then warn that plyxp dplyr methods have likely been overwritten!
# # otherwise, let the .onAttach method warn the user
# cli::cli_inform(
# .frequency = "regularly",
# .frequency_id = "tidySummarizedExperiment_loaded_after_plyxp_attach",
# class = "plyxp_loaded_conflict",
# message = c(
# "!" = paste0(
# "You have likely loaded {.pkg tidySummarizedExperiment} after ",
# "{.pkg plyxp} via {.code tidySummarizedExperiment::...}"
# ),
# "*" = paste(conflict_info, collapse = ""),
# "!" = "This has likely caused {.pkg dplyr} methods from {.pkg plyxp} to be over-written!",
# "i" = "If this wasn't your intention, consider restarting your R session"))
# }

.onAttach <- function(libname, pkgname) {
# check if `tidySummarizedExperiment` is already loaded
conflict <- grep("tidySummarizedExperiment", search(), value = TRUE)
if (length(conflict)) {
you_have_loaded("plyxp","tidySummarizedExperiment",
.class = c("packageStartupMessage", "message"))
}
# set hook for if `tidySummarizedExperiment` gets attached latter
setHook(
packageEvent(pkgname = "tidySummarizedExperiment",
event = "attach"),
function(...) {
you_have_loaded("tidySummarizedExperiment","plyxp",
.class = c("packageStartupMessage", "message"))
}

)
# hook for when tidySummarizedExperiment:: is used after plyxp is attached
setHook(
packageEvent(pkgname = "tidySummarizedExperiment",
event = "onLoad"),
function(...) {
calls <- sys.calls()
called_via_library <- vapply(calls, attaching_tidySE, logical(1))
if (!any(called_via_library)) {
# if this callback was not executed via library(tidySummarizedExperiment)
# then warn that plyxp dplyr methods have likely been overwritten!
# otherwise, let the .onAttach method warn the user
cli::cli_inform(
.frequency = "regularly",
.frequency_id = "tidySummarizedExperiment_loaded_after_plyxp_attach",
class = "plyxp_loaded_conflict",
message = c(
"!" = paste0(
"You have likely loaded {.pkg tidySummarizedExperiment} after ",
"{.pkg plyxp} via {.code tidySummarizedExperiment::...}"
),
"*" = paste(conflict_info, collapse = ""),
"!" = "This has likely caused {.pkg dplyr} methods from {.pkg plyxp} to be over-written!",
"i" = "If this wasn't your intention, consider restarting your R session"))
}

}
)
}
# }
# )
# }

.onDetach <- function(libpath) {
# remove verbose message when `plyxp` is removed from attach list
setHook(packageEvent("tidySummarizedExperiment", "attach"), NULL, "replace")
setHook(packageEvent("tidySummarizedExperiment", "onLoad"), NULL, "replace")
}
# .onDetach <- function(libpath) {
# # remove verbose message when `plyxp` is removed from attach list
# setHook(packageEvent("tidySummarizedExperiment", "attach"), NULL, "replace")
# setHook(packageEvent("tidySummarizedExperiment", "onLoad"), NULL, "replace")
# }

# check_dplyr_s3_method <- function(method) {
# tbl <- getNamespace("dplyr")[[".__S3MethodsTable__."]]
Expand Down

0 comments on commit b6287e3

Please sign in to comment.