I'm developing an ecosystem of packages similar to (and inspired by) the tidyverse. As I refactor a function [say fun1()
] in one package I may be breaking other packages. My goal is to quickly find and re-test those broken packages.
I wonder if there is any function [maybe a wrapper around remotes::dev_package_deps()
] that specifically returns the packages that call a specific function [e.g. fun1()
]. How do the tidyverse team go about this problem?
So far my solution finds not functions but packages to focus on. Say that I refactored a package called mypkg.n; this is how I find other packages in my ecosystem mypkg that depend on mypkg.n:
# Argument `root` assumes that all packages of the ecosystem __mypkg__ have the same parent directory.
mypkg_package_deps <- function(pkg,
root = "../",
mypkg_pkgs = c("mypkg.1", "mypkg.2"))) {
mypkg_deps <- list_mypkg_deps(root, mypkg_pkgs)
deps_matching_pkg <- purrr::keep(mypkg_deps, ~any(grepl(pkg, .)))
names(deps_matching_pkg)
}
list_mypkg_deps <- function(root, mypkg_pkgs) {
paths <- paste0(root, mypkg_pkgs)
all_deps <- purrr::map(paths, remotes::local_package_deps, TRUE)
all_deps <- purrr::set_names(all_deps, mypkg_pkgs)
mypkg_deps <- purrr::map(all_deps, ~intersect(., mypkg_pkgs))
mypkg_deps
}