R Package installed or not

0 votes
How to find the list of already installed packages and show installed and not installed in R Script?
Jun 27 in Data Analytics by vinod
21 views

2 answers to this question.

0 votes

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!

answered Jun 27 by Cherukuri
• 31,840 points
0 votes
To see all installed packages in system use installed.packages().

It will give you a very big list of all packages, version and the path for each package in a list like below which is not much preferred.
answered Jun 27 by anonymous
• 31,840 points

Related Questions In Data Analytics

0 votes
1 answer

Error saying "R Error: package ‘lme4’ required by ‘pbkrtest’ could not be found"

Windows 7, revo R 3.2.3 construct a directory ...READ MORE

answered Nov 9, 2018 in Data Analytics by Maverick
• 10,040 points
40 views
0 votes
1 answer
0 votes
0 answers
0 votes
0 answers

Error: package or namespace load failed for ‘arulesViz’ in R

Hi, im getting below error while installing ...READ MORE

Jul 8 in Data Analytics by ramya
53 views
0 votes
1 answer

By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
112 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
157 views
0 votes
1 answer

In a dpylr pipline how to use sample and seq?

For avoiding rowwise(), I prefer to use ...READ MORE

answered Apr 6, 2018 in Data Analytics by DeepCoder786
• 1,720 points
82 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
98 views
0 votes
1 answer

Check palindrome or not in R

Hi, I found this code simple and easy. is_palindrome ...READ MORE

answered Aug 20 in Data Analytics by anonymous
• 31,840 points
29 views
0 votes
1 answer

Error: package or namespace load failed for ‘ggplot2’ - R

Radha, Try restarting the session. the same ...READ MORE

answered Aug 30 in Data Analytics by anonymous
• 31,840 points
88 views