R语言基础:如何安包?

写在前面:R与Rstudio是生信的基础(包括Rtools),必须安装于C盘,且用户名为英文。建议安装时设置为英语语言。取消勾选message translation,免得后续麻烦。

1.镜像设置

1.1旧办法,对于R版本<4.4

具体可参考:周末生物信息学培训班准备工作 | 生信菜鸟团

安装R包,在中国必须使用镜像,我使用了AI对程序进行注释:

rm(list = ls()) 
options()$repos 
options()$BioC_mirror
#options(BioC_mirror="https://mirrors.ustc.edu.cn/bioc/")
options(BioC_mirror="http://mirrors.tuna.tsinghua.edu.cn/bioconductor/")
options("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/"))
options()$repos 
options()$BioC_mirror
  • rm(list = ls()): 清空当前R工作空间中的所有对象(变量、函数等)。

  • options()$repos: 显示当前配置的R包安装的仓库选项。默认情况下,它显示当前为R包配置的仓库。

  • options()$BioC_mirror: 显示当前Bioconductor镜像(仓库),R将使用它来安装Bioconductor包。

  • options(BioC_mirror="http://mirrors.tuna.tsinghua.edu.cn/bioconductor/"): 将Bioconductor镜像设置为使用清华大学的镜像来安装Bioconductor包。Bioconductor是专门用于生物信息学包的仓库。

  • options("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/")): 将CRAN镜像设置为使用清华大学的镜像来安装R包。CRAN(综合性R档案网络)是R包的主要仓库。

  • options()$repos: 设置了仓库后,此命令显示更新后的R包安装的仓库选项。

  • options()$BioC_mirror: 设置了Bioconductor镜像后,此命令显示更新后的Bioconductor镜像,R将使用它来安装相关包。

1.2对于R版本>4.4,可通过Rstudio设置镜像,不用每次运行

1.3若需要R4.4以下的包,需要西湖大学镜像

因为其他镜像删除了低版本bio_conductor的包

options("repos"=c(CRAN="http://mirrors.tuna.tsinghua.edu.cn/CRAN/"))
# 备用:西湖大学
options(BioC_mirror="https://mirrors.westlake.edu.cn/bioconductor")

2.如何安包?

R包主要来源于3个库,CRAN,Bioconductor和github。

接下来就是包的安装:安装包需要使用“”文本形式,而library函数则不用。

CRAN的包安装非常简单,仅需: 

install.packages("stringr")

 Bioconductor则需先安装BiocManager:

install.packages('BiocManager') #先安装BiocManager,才能用BiocManager装其他的包。
BiocManager::install("limma")

 还有从github中安装R包

install.packages("devtools")
devtools::install_github("用户名/包")

 如果不确定有的包是否安装,可以调用以下命令安装:

if(!require(stringr))install.packages("stringr")

3.以下是r语言生信中推荐安装的:

options()$repos
install.packages('WGCNA')
install.packages(c("FactoMineR", "factoextra"))
install.packages(c("ggplot2", "pheatmap","ggpubr"))
library("FactoMineR")
library("factoextra")

library(GSEABase)
library(GSVA)
library(clusterProfiler)
library(ggplot2)
library(ggpubr)
library(hgu133plus2.db)
library(limma)
library(org.Hs.eg.db)
library(pheatmap)

4.如何获取帮助

?sd#函数的说明
browseVignettes("limma") #包的在线教程
ls("package:limma")#包内函数明细

包括网页搜索R包介绍:

 大家也可参考b站中较新的教程:可能是最好用的R包安装教程_哔哩哔哩_bilibili

注:每次安装后建议使用library函数进行检查。同时不用管warning!!!只要不是error,一切都OK!!!

附上: R包安装与使用的常见问题和解决方法速查

引用自生信技能树。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值