Remove all packages that do not come with R

2019-03-24 16:20发布

How can I remove all installed packages except base and recommended?

标签: r package
4条回答
对你真心纯属浪费
2楼-- · 2019-03-24 17:08

Instead of

Updated to R 3.0.0 and have to rebuild all packages.

just do

update.packages(..., checkBuilt=TRUE)

which is what I did on my R 3.0.0 (using lib.loc=... to point to my different local directories). This will update everything you have and which it can still get from repos such as CRAN. For install_git() etc, you are out of luck and need to reinstall.

But either way you do not need to remove the packages first.

查看更多
爷的心禁止访问
3楼-- · 2019-03-24 17:14

Be CAREFUL! And read the docs before you try this:

# Pasted as a commented to prevent blindly copying and pasting
# remove.packages( installed.packages( priority = "NA" )[,1] )

By default this will remove packages from the first library in your .libPaths().

查看更多
放荡不羁爱自由
4楼-- · 2019-03-24 17:14

If on Linux, the easiest thing is probably to remove the library folder, which by default is located in /home/yourusername/R.

On Fedora, for example, it is called x86_64-redhat-linux-gnu-library. If the folder /home/yourusername/R/x86_64-redhat-linux-gnu-library is deleted, it is automatically recreated at the following start of R. All default libraries are regularly available.

查看更多
姐就是有狂的资本
5楼-- · 2019-03-24 17:24

Here is a solution available in the R-Blogger:

# create a list of all installed packages
 ip <- as.data.frame(installed.packages())
 head(ip)
# if you use MRO, make sure that no packages in this library will be removed
 ip <- subset(ip, !grepl("MRO", ip$LibPath))
# 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)

Here is the link for the original post: https://www.r-bloggers.com/how-to-remove-all-user-installed-packages-in-r/

查看更多
登录 后发表回答