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, 2019 in Data Analytics by vinod
914 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, 2019 by Cherukuri
• 33,030 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, 2019 by anonymous
• 33,030 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,840 points
767 views
0 votes
1 answer
0 votes
0 answers

Error: package or namespace load failed in R

Hi, I want to use dplyr package ...READ MORE

Jul 8, 2019 in Data Analytics by ramya
1,543 views
0 votes
1 answer

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

I installed package KernSmooth and it seemed ...READ MORE

answered Sep 4, 2020 in Data Analytics by Chandrakant
• 140 points
1,242 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
2,219 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
1,882 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

edited Jun 9, 2020 by Gitika 1,144 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
1,287 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 21, 2019 in Data Analytics by anonymous
• 33,030 points
7,125 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, 2019 in Data Analytics by anonymous
• 33,030 points
3,714 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP