太長不看版
只需要使用BiocManager::install()
就可以把CRAN
、bioconductor
测暗、GitHub
來源的包都安裝上了。
R包安裝的天下三分
安裝R包是每個(gè)學(xué)習(xí)R語言的同學(xué)都繞不開的一環(huán)磨澡。
現(xiàn)在R包主要的來源有三個(gè):
CRAN
bioconductor
-
GitHub
碗啄。
按照比較經(jīng)典的方法,三種來源的包應(yīng)該對(duì)應(yīng)三種安裝方式:
- CRAN包:
使用install.packages函數(shù)安裝:
install.packages("ggplot2")
- Bioconductor包:
使用BiocManager::install函數(shù)安裝:
BiocManager::install("GenomicRanges")
- GitHub包:
使用devtools安裝:
devtools::install_github("hadley/httr")
用錯(cuò)了安裝的命令會(huì)怎樣钱贯?
如果你選錯(cuò)了命令挫掏,例如用CRAN的安裝方式去安裝Bioconductor里的GenomicRanges
包:
> install.packages("GenomicRanges")
可能會(huì)遇到這樣的報(bào)錯(cuò):
Warning in install.packages :
package ‘GenomicRanges’ is not available for this version of R
A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-package
報(bào)錯(cuò)“忽悠”你GenomicRanges
這個(gè)包在當(dāng)前版本的R不可用。如果你去升級(jí)/降級(jí)你的R版本秩命,那就算是掉進(jìn)死胡同里了尉共。
天下三分,合歸一統(tǒng)
實(shí)際上弃锐,BiocManager::install()
就可以安裝所有三個(gè)來源的包了袄友。
CRAN上的包
例如CRAN上的經(jīng)典包ape:
BiocManager::install("ape")
BiocManager就可以自己到CRAN里去把包裝上:
'getOption("repos")' replaces Bioconductor standard repositories, see 'help("repositories", package = "BiocManager")'
for details.
Replacement repositories:
CRAN: https://cran.wustl.edu/
Bioconductor version 3.17 (BiocManager 1.30.21), R 4.3.1 (2023-06-16 ucrt)
Installing package(s) 'ape'
trying URL 'https://cran.wustl.edu/bin/windows/contrib/4.3/ape_5.7-1.zip'
Content type 'application/zip' length 3405117 bytes (3.2 MB)
downloaded 3.2 MB
package ‘a(chǎn)pe’ successfully unpacked and MD5 sums checked
GitHub上的包
包括GitHub上的包,你只要把作者/倉庫名
寫進(jìn)括號(hào)里就可以了霹菊。
倉庫地址:
'getOption("repos")' replaces Bioconductor standard repositories, see 'help("repositories", package = "BiocManager")'
for details.
Replacement repositories:
CRAN: https://cran.wustl.edu/
Bioconductor version 3.17 (BiocManager 1.30.21), R 4.3.1 (2023-06-16 ucrt)
Installing github package(s) 'r-lib/httr'
Downloading GitHub repo r-lib/httr@HEAD
就裝好了剧蚣。
注意支竹,你得先安裝上remotes這個(gè)包才能安裝GitHub上的包:
BiocManager::install("remotes")
根據(jù)這個(gè)remotes包的介紹,其實(shí)除了GitHub之外的其他類似平臺(tái)也是可以安裝的鸠按,例如GitLab和Bitbucket礼搁。
Download and install R packages stored in 'GitHub', 'GitLab', 'Bitbucket', 'Bioconductor', or plain 'subversion' or 'git' repositories.
萌哥碎碎念
- 最近在學(xué)R語言,突然發(fā)現(xiàn)R在某些方面比SHELL似乎確實(shí)是優(yōu)雅了不少目尖。用SHELL寫可能吭哧吭哧半天成果還是個(gè)半成品馒吴,R可能咔咔就整完了。
- 現(xiàn)在越來越傾向于多種語言混合做數(shù)據(jù)分析瑟曲,用Rstudio開一個(gè)Rmarkdown饮戳,啥python啊R啊SHELL啊都往里面招呼,確實(shí)還蠻過癮的洞拨。博采眾長嘛扯罐。
- 以前最怕的是遇到問題查不到結(jié)果,現(xiàn)在有GPT了大部分的錯(cuò)誤直接把報(bào)錯(cuò)貼給GPT它就給你分析出結(jié)果了烦衣,確實(shí)是實(shí)實(shí)在在地提高了生產(chǎn)力歹河。