To unload the package in R, you can use unloadNamespace() function.

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

Method 1: Use unloadNamespace() Function

unloadNamespace("Package_name")

The following example shows how to unload package in R using unloadNamespace() function.

Using unloadNamespace() Function

Let’s see how we can use unloadNamespace() function in R:

# Unload package
unloadNamespace("tidyr")

Here in the above code we unload the tidyr package using unloadNamespace() function.