I have extended the solution of @GSW's answer by also considering other types of dependencies from the rJAva
package:
libs = installed.packages()
imports = grep("Java", libs[,"Imports"], ignore.case=TRUE)
depends = grep("Java", libs[,"Depends"], ignore.case=TRUE)
linking.to = grep("Java", libs[,"LinkingTo"], ignore.case=TRUE)
enhances = grep("Java", libs[,"Enhances"], ignore.case=TRUE)
# SystemRequirements may also contain Java dependencies but is not available in the matrix
libs[c(imports, depends, linking.to, enhances),
c("Package", "Imports", "Depends", "LinkingTo", "Enhances")]
This now also finds eg. xlsx
:
Package Imports Depends LinkingTo Enhances
xlsx "xlsx" NA "rJava, xlsxjars" NA NA
xlsxjars "xlsxjars" NA "rJava" NA NA
Edit Dec 21, 2021: If you want to find all CRAN packages (not only the installed ones) that directly depend on JAVA (eg. due to log4j
vulnerability) you can use:
# Dependencies external to the R system should be listed in the `SystemRequirements` field of the package's DESCRIPTION file.
# This also holds true until the package uses Java via the rJava package where the `Imports` or `Depends` declaration suffices:
# https://cran.r-project.org/doc/manuals/R-exts.html#Non_002dR-scripts-in-packages
CRAN.pkgs <- tools::CRAN_package_db() # gets a list of all R packages at CRAN
imports = grepl("Java", CRAN.pkgs$Imports, ignore.case = TRUE)
depends = grepl("Java", CRAN.pkgs$Depends, ignore.case = TRUE)
linking.to = grepl("Java", CRAN.pkgs$LinkingTo, ignore.case = TRUE)
enhances = grepl("Java", CRAN.pkgs$Enhances, ignore.case = TRUE)
sysreq = grepl("Java", CRAN.pkgs$SystemRequirements, ignore.case = TRUE)
CRAN.java.pkgs <- CRAN.pkgs[imports | depends | linking.to | enhances | sysreq,
c("Package", "Imports", "Depends", "LinkingTo", "Enhances", "SystemRequirements")]
NROW(CRAN.pkgs) # more than 18.000 in 12/2021
NROW(CRAN.java.pkgs) # 137 in 12/2021
CRAN.java.pkgs$Package # show all packages found