library(stringi) library(hrbrthemes) library(tidyverse) # All the pkgs from the home CRAN mirror that import 'dbplyr' c( "arkdb", "bigrquery", "childesr", "chunked", "civis", "corrr", "cytominer", "dbplot", "dbplyr", "dexter", "dexterMST", "dlookr", "dplyr", "dplyr.teradata", "etl", "healthcareai", "hydrolinks", "implyr", "infuser", "ipumsr", "macleish", "mdsr", "mlbgameday", "modeldb", "MonetDBLite", "mudata2", "parsemsf", "pivot", "pleiades", "pool", "poplite", "RClickhouse", "replyr", "RPresto", "sergeant", "sparklyr", "sqlscore", "srvyr", "taxizedb", "valr", "wordbankr", "metis.tidy" ) -> pkgs # I ended up doing install.pkgs(pkgs) # ^^ doesn't mean they implement a back-end, so we have to load their namespaces # and see if they have the "tell" (i.e. they implement `sql_translate()`) map_df(pkgs, ~{ tibble( pkg = .x, trans = loadNamespace(.x) %>% names() %>% keep(stri_detect_fixed, "sql_translate") ) }) -> xdf # now we iterate through them, ignoring the NULL and Pool connection classes filter(xdf, stri_detect_fixed(trans, ".")) %>% filter(trans != "sql_translate_env.NULL") %>% filter(trans != "sql_translate_env.Pool") %>% mutate(ƒ = map(trans, ~{ # get the sql translate functions con <- NA cls <- stri_replace_first_fixed(.x, "sql_translate_env.", "") class(con) <- cls env <- sql_translate_env(con) # but ^^ rly isn't a nice, tidy object, it's a list of environments # with functions in it so we have to iterate through it to extract # the function names. map_df(env, ~{ part <- .x fs <- names(part) # but it's not just good enough to do that b/c a given function name # might just implement the "sql_not_supported()" pass through. So we have # to actually look to see if the function body has a "stop()" call in it # and ignore it if it does. map_df(fs, ~{ tibble(ƒ = .x, src = paste0(as.character(body(part[[.x]])), collapse = "; ")) %>% filter(!stri_detect_fixed(src, "stop(")) %>% filter(stri_detect_regex(ƒ, "[[:alpha:]]")) %>% # and we rly don't care about maths select(-src) }) }) })) -> xdf # now it's just ggplot2 magic unnest(xdf, ƒ) %>% mutate(trans = stri_replace_first_fixed(trans, "sql_translate_env.", "")) %>% mutate(db = glue::glue("{pkg}\n{trans}")) %>% # make something useful to display for the DB/conn arrange(ƒ) %>% mutate(n = 1) %>% complete(db, ƒ) %>% # complete the heatmap mutate(ƒ = factor(ƒ, levels=rev(unique(ƒ)))) %>% # arrangfe the Y axis in the proper order filter(stri_detect_regex(ƒ, "[[:alpha:]]")) %>% # not necessary but this was in iteration 1 so I just left it ggplot(aes(db, ƒ)) + geom_tile(aes(fill = n), color="#2b2b2b", size=0.125, show.legend=FALSE) + scale_x_discrete(expand=c(0,0.1), position = "top") + scale_fill_continuous(na.value="white") + labs( x = NULL, y = NULL, title = "SQL Function Support In Known d[b]plyr Backends" ) + theme_ipsum_ps(grid="", axis_text_size = 9) + theme(axis.text.y = element_text(family = "mono", size = 7))