Hi Vinod,
Try below code -
list_packages = c("Rserve","ggplot2","rmarkdown","Shiny")
status_final = c()
i=1
installed = substring(find.package(list_packages,quiet = TRUE),55)
status = list_packages %in% installed # to check which are installed from the package list.
for (stt in status){ # to print which pacakage is installed and which is not installed in a loop for each package.
if (stt == "FALSE")
status_final[i] = "Not installed"
else
status_final[i] = "installed"
i=i+1
}
Explanation to the code -
list_packages is a list of packages that you want to check whether installed or not.
status_final stores the status whether installed or not installed.
installed list store the list of package that are installed.
find.package() is used to find the list of packages that are installed in system which takes parameters as below
find.package(package, quiet = TRUE)
where package is a vector of all packages neede to be found.
quiet is used to determine whether to show warning of unfound packages or not.
The result of find.package is a ist of all paths of found packages.
substring() is used to fetch the package names from the list of paths which is stores in installed.
This list is then checked with all the package and then checked using if to find the uninstalled packages.
Output - Run the source R Script.
Then print the installed list to show installed packages.
Hope it helps!