To check if package is installed in R, you can use the installed.packages().

The following method shows how you can do it with syntax.

Method: Use installed.packages() Function

package_name %in% rownames(installed.packages())

The following example shows how to check if package installed or not in R.

Using installed.packages() Function

Let’s check if data.table package is installed or not in R:

# Declare package
package <- "data.table"

# Check package installed or not 
package %in% rownames(installed.packages())


[1] TRUE

Here the output shows TRUE which means data.table package is installed in R.