简洁全面总结 R-安装卸载及加载卸除包
安装
三个开放源:
CRAN(R语言官网) 链接: Bioconductor 链接: Github 链接:
五种方法:
1、R官网(CRAN)直接下载安装
直接下载安装所需R包,如安装readr:
install.packages(readr)
2、Bioconductor下载安装
如R官网无所需包,可选用Bioconductor,需先安装BiocManager包,再用BiocManager包install函数安装所需包,如安装Rsubread:
install.packages(edgeR,repos="https://mirrors.tuna.tsinghua.edu.cn/CRAN/") if (!require("BiocManager", quietly = TRUE)) install.packages("BiocManager") BiocManager::install("Rsubread")
3、Github下载安装
若前两种未安装成功,可考虑使用Github安装,需先安装devtools包,再用devtools包install_github函数安装,且需要在其前加上该包所在的库名,如安装ggplot2:
install.packages(devtools) library(devtools) install_github(tidyverse/ggplot2)
4、conda安装
省心的办法,直接conda安装,如安装ggplot2
conda search r-ggplot2 conda install r-ggplot2 -c bioconda
5、手动将R包安装。
手动获得安装包,借助install.packages()函数安装,如安装ggplot2
download.file("http://cran.r-project.org/src/contrib/Archive/ggplot2/ ggplot2_3.3.5.tar.gz"," ggplot2_3.3.5.tar.gz") install.packages("ggplot2_3.3.5.tar.gz", repos = NULL)
查看已安装包
installed.packages()
查看包提供的函数
help(package=ggplot2)
卸载
彻底删除包: remove. packages(“ggplot2” , lib = file .path(“/usr/local/lib/R/library”))
加载
查看已加载包
(.packages())
卸除加载包
卸除已经加载到内存的包,卸除不是卸载,只是存储释放。
detach(“package:ggplot2”)