Closed duttashi closed 6 years ago
Solution
# Objective 1: Set the library path for installed packages
# Objective 2: To uninstall all packages and then install only the relevant ones
# create a list of all installed packages
ip <- as.data.frame(installed.packages())
head(ip)
# we don't want to remove base or recommended packages either\
ip <- ip[!(ip[,"Priority"] %in% c("base", "recommended")),]
# determine the library where the packages are installed
path.lib <- unique(ip$LibPath)
# create a vector with all the names of the packages you want to remove
pkgs.to.remove <- ip[,1]
head(pkgs.to.remove)
# remove the packages
sapply(pkgs.to.remove, remove.packages, lib = path.lib)
# check the R library path
.libPaths()
# set the library path for R
.libPaths("C:/Program Files/R/R-3.5.0/library")
# set the library path for Rstudio
assign(".lib.loc", "C:/Program Files/R/R-3.5.0/library", envir = environment(.libPaths))
# check the R library path again
.libPaths()
# Now, installing multiple packages required for analysis
pkgs_to_install<- c("caret","cluster","tidyverse","grid",
"RColorBrewer","factoextra","ggpubr","FactoMineR")
install.packages(pkgs_to_install, dependencies = TRUE)
References
I was still getting error when loading a library in RStudio. My mistake was that earlier, I had set up the library path but it was set for R and not RStudio. So, I had to include the following line in the .RProfile site as well as whenever I would want to install a package in Rstudio, I've to use the following command, assign(".lib.loc", "C:/Program Files/R/R-3.5.0/library", envir = environment(.libPaths))
Reference
Last evening I decided to update the installed packages. During the update process, a prompt came up,
do you want to install from sources the packages which need compilation r
. I chose the option,yes
and boy, this messed up everything in RStudio.Lesson learnt: if such a message pop's up, choose
No
. See this post for reference.Another problem was I had never set up the library path for the installed packages. So, I needed to set the library path. And finally, I needed to tweak the
.Rprofile.site
file. For windows OS it is located in,C:\Program Files\R\R-3.5.0\etc