Possible causes
There could be many reasons as to why it is happening.
In my case, remove.packages("somepackagehere")
was not working because the current system user that I am using doesn't have write
privileges to the packages I want to uninstall. So, this is a possible reason for computers/machines with multiple users using R.
Checking the location of packages
This can be checked by issuing the statement in the R console:
.libPaths()
output
[1] "/Library/Frameworks/R.framework/Versions/4.0/Resources/library"
The directory output may vary per R installation. This is just for my case. The directory output is where the installed packages were stored. It may look different for Windows systems.
Checking privileges
In Mac and Linux, the privileges can be checked by:
cd /Library/Frameworks/R.framework/Versions/4.0/Resources/library
ls -la
output
drwxrwxr-x 422 root admin 13504 Apr 21 19:13 .
drwxrwxr-x 18 root admin 576 Jul 16 2020 ..
drwxr-xr-x 3 mario admin 96 Jun 17 2021 RODBC
drwxr-xr-x 3 mario admin 96 Jun 17 2021 dplyr
In this case, it was mario
who installed the packages. Since I --luigi
-- was currently using the machine, I can not remove those packages. It is only mario
that can do it.
In Windows, I have no clue as to how it can be checked.
Granting privileges
cd /Library/Frameworks/R.framework/Versions/4.0/Resources/library
sudo chown -R luigi:admin .
OR
cd /Library/Frameworks/R.framework/Versions/4.0/Resources/library
sudo chmod -R o+w .
In Windows, I have no clue as to how privileges can be granted.
Removing packages
Finally, with the correct privileges, you can now remove the packages like so:
remove.packages("RODBC")