You can do what R does for you by relying on some public information:
> db <- tools::CRAN_package_db() # a big matrix with all packages
> deps <- tools::package_dependencies("ggplot2", recursive=TRUE, db=db)
> deps # a list as you could have called with more than arg
$ggplot2
[1] "digest" "glue" "grDevices" "grid" "gtable"
[6] "isoband" "MASS" "mgcv" "rlang" "scales"
[11] "stats" "tibble" "withr" "utils" "methods"
[16] "graphics" "nlme" "Matrix" "splines" "farver"
[21] "labeling" "lifecycle" "munsell" "R6" "RColorBrewer"
[26] "viridisLite" "fansi" "magrittr" "pillar" "pkgconfig"
[31] "vctrs" "lattice" "colorspace" "cli" "utf8"
>
So by calling the package_dependencies
(base R) function you get the list of all dependencies, either level one or fully recursively.
You could then check this with installed.packages()
to see what if anything is missing in the local installation.