轉自生信師兄
生信必備技巧之R語言基礎教程
1. 學習資源
-
推薦書籍:R語言實戰,R數據科學等等;
這兩本書在公眾號【生信師兄】都有pdf版,有需要的可以關注公眾號【生信師兄】并回復:“R語言”,即可獲得免費電子版書籍。
-
遇見bug怎么辦
-
R語言初學者必備-cheatsheet大全:https://www.rstudio.com/resources/cheatsheets/
-
R語言菜鳥教程:https://www.runoob.com/r/r-tutorial.html
-
簡書、知乎等各大平臺都會提供很多生信分析常見的教程,一定要利用好這些資源;
-
報錯怎么辦:度娘來幫忙;一定要學會百度!一定要學會百度!一定要學會百度!
-
2. 了解并安裝R, Rstudio 及R包
-
下載R語言的軟件: https://cran.r-project.org/bin
-
下載Rstudio這個R編輯器: https://www.rstudio.com/products/rstudio/download/
-
安裝一些必要的包:
-
什么是R包:包是 R 函數、實例數據、預編譯代碼的集合,包括 R 程序,注釋文檔、實例、測試數據等;
-
安裝包 install.packages(" xxxxxx ")
對于生物信息學常用的包,可以使用:BiocManager::install(“xxxx”)函數進行安裝
-
加載包 library( xxxxx )
-
查看包的幫助文檔help(“xxxxx”) 或?xxxxx
-
# 生物信息學分析必備的一些R包,復制以下代碼,直接運行即可;
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# 方法一:
options()$repos
install.packages('WGCNA')
install.packages(c("FactoMineR", "factoextra"))
install.packages(c("ggplot2", "pheatmap","ggpubr"))
library("FactoMineR")
library("factoextra")# 方法二:
if (!requireNamespace("BiocManager", quietly = TRUE))install.packages("BiocManager")
BiocManager::install("KEGG.db",ask = F,update = F)
BiocManager::install(c("GSEABase","GSVA","clusterProfiler" ),ask = F,update = F)
BiocManager::install(c("GEOquery","limma","impute" ),ask = F,update = F)
BiocManager::install(c("org.Hs.eg.db","hgu133plus2.db" ),ask = F,update = F)# 方法三:從github中安裝# 所有的R包都提交上傳到CRAN,如Github,需要通過一定的渠道進行安裝
# R安裝devtools包
install.packages("devtools")
library(devtools)
# 安裝github上的R包(需翻墻或改hosts)
devtools::install_github('lchiffon/REmap')
# 前為github的用戶名,后為包名# 測試--加載R包;
library(REmap)
library(GSEABase)
library(GSVA)
library(clusterProfiler)
library(ggplot2)
library(ggpubr)
library(hgu133plus2.db)
library(limma)
library(org.Hs.eg.db)
library(pheatmap)
-
獲取當前工作區間getwd()
-
更改工作區間setwd( “xxxxxx”)
-
清除當前對象rm(xx)