-2

I am trying to make a personal R-function.

I want add if statement which can check whether essential R packages are installed.

I used exist() function but its purpose is to examine existence of an object so it didn't work.

Is there a basic command for checking existence of a specific R-package in R?

Thx

Sejin
  • 85
  • 9

2 Answers2

2

You are looking for installed.packages() That will list all installed packages. Another option is require(thepackage) which will either load the package or return FALSE if the 'thepackage' is not available.

Thierry
  • 18,049
  • 5
  • 48
  • 66
0

A way to do specifically what you asked is

"Package-Name" %in% installed.packages() which will return TRUE or FALSE depending on whether or not "Package-Name" is installed.

However, if you're writing a script, you will usually want to use

library(Package-Name) or require(Package-Name)

If the package is installed, both will load it. If it isn't, library will throw an error, require will return FALSE and give a warning.

hdkrgr
  • 1,666
  • 1
  • 12
  • 22