Comments (2)
Potentially also draw from tidymodels::tidymodels_prefer()
and have a greta_prefer()
. This means you won't need to manage library order, or use conflicted
. One use case of this is when %*%
gets overwritten from greta
from greta.
Some basic code stolen from tidyverse_conflicts()
#' Conflicts between the greta and other packages
#'
#' This function lists all the conflicts between packages in the greta
#' and other packages that you have loaded.
#'
#' There are XX conflicts that are deliberately ignored: \code{XX},
#' \code{union}, \code{setequal}, and \code{setdiff} from greta. reasons
#'
#' @export
#' @param only Set this to a character vector to restrict to conflicts only
#' with these packages.
#' @examples
#' greta_conflicts()
greta_conflicts <- function(only = NULL) {
envs <- grep("^package:", search(), value = TRUE)
envs <- purrr::set_names(envs)
if (!is.null(only)) {
only <- union(only, core)
envs <- envs[names(envs) %in% paste0("package:", only)]
}
objs <- invert(lapply(envs, ls_env))
conflicts <- purrr::keep(objs, ~ length(.x) > 1)
tidy_names <- paste0("package:", greta_packages())
conflicts <- purrr::keep(conflicts, ~ any(.x %in% tidy_names))
conflict_funs <- purrr::imap(conflicts, confirm_conflict)
conflict_funs <- purrr::compact(conflict_funs)
structure(conflict_funs, class = "greta_conflicts")
}
greta_conflict_message <- function(x) {
header <- cli::rule(
left = cli::style_bold("Conflicts"),
right = "greta_conflicts()"
)
pkgs <- x %>% purrr::map(~ gsub("^package:", "", .))
others <- pkgs %>% purrr::map(`[`, -1)
other_calls <- purrr::map2_chr(
others, names(others),
~ paste0(cli::col_blue(.x), "::", .y, "()", collapse = ", ")
)
winner <- pkgs %>% purrr::map_chr(1)
funs <- format(paste0(cli::col_blue(winner), "::", cli::col_green(paste0(names(x), "()"))))
bullets <- paste0(
cli::col_red(cli::symbol$cross), " ", funs, " masks ", other_calls,
collapse = "\n"
)
conflicted <- paste0(
cli::col_cyan(cli::symbol$info), " ",
cli::format_inline("Use the {.href [conflicted package](http://conflicted.r-lib.org/)} to force all conflicts to become errors"
))
paste0(
header, "\n",
bullets, "\n",
conflicted
)
}
#' @export
print.greta_conflicts <- function(x, ..., startup = FALSE) {
cli::cat_line(greta_conflict_message(x))
invisible(x)
}
#' @importFrom magrittr %>%
confirm_conflict <- function(packages, name) {
# Only look at functions
objs <- packages %>%
purrr::map(~ get(name, pos = .)) %>%
purrr::keep(is.function)
if (length(objs) <= 1)
return()
# Remove identical functions
objs <- objs[!duplicated(objs)]
packages <- packages[!duplicated(packages)]
if (length(objs) == 1)
return()
packages
}
ls_env <- function(env) {
x <- ls(pos = env)
# intersect, setdiff, setequal, union come from generics
if (env %in% c("package:dplyr", "package:lubridate")) {
x <- setdiff(x, c("intersect", "setdiff", "setequal", "union"))
}
if (env == "package:lubridate") {
x <- setdiff(x, c(
"as.difftime", # lubridate makes into an S4 generic
"date" # matches base behaviour
))
}
x
}
.onAttach <- function(...) {
attached <- tidyverse_attach()
if (!is_loading_for_tests()) {
inform_startup(tidyverse_attach_message(attached))
}
if (!is_attached("conflicted") && !is_loading_for_tests()) {
conflicts <- tidyverse_conflicts()
inform_startup(tidyverse_conflict_message(conflicts))
}
}
from greta.
Related Issues (20)
- Provide more details in `greta_sitrep()` to assist with debugging
- greta_sitrep() fails, despite github install_great_deps() reporting no errors HOT 5
- Update R Depends HOT 1
- Capture errors in misspelt argument names
- calculate() hangs with NaN parameters in sampling distribution in tf2 branch HOT 3
- `mcmc` failed in R 4.3.3 HOT 2
- use `cli::test_that_cli()` for testing cli output
- Literature on Greta HOT 1
- Speed up testing in greta HOT 1
- data frame printing and overwriting methods for greta arrays
- use rhub 2.0
- Some git hygiene
- opt() errors with "Error in as.numeric(tfe$tf_optimiser$iterations): cannot coerce type 'environment' to vector of type 'double'" HOT 1
- calculating a wishart behaves differently pre and post MCMC
- Use `%||%` to replace `if (is.null(x)) {do else}` pattern
- Use "explaining variables" in `if` statements or other places
- Explore python installation process in `rgee`
- A note on keras 2 and keras 3
- `calculate()` errors if user working environment has an object called `batch_size` HOT 2
- Identify which known versions sets of TF, TFP, and Python work for greta
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from greta.