R及R包安装、更新、卸载、删除

您所在的位置:网站首页 然后删除安装包 R及R包安装、更新、卸载、删除

R及R包安装、更新、卸载、删除

2023-10-20 20:29| 来源: 网络整理| 查看: 265

更新R version #查看现有R版本 install.packages("installr") library("installr") updateR() #安装并加载installr包,并调用里面的函数updateR() 更新R包 更新所有R包 如果用的是Rstudio,要更新library里所有包,一种方法是点击Tools,选择Check for Package Updates即可。 另外也可使用update.packages()函数实现。 #检查library里哪些包有更新版本 old.packages() #更新library里所有包 update.packages() 更新指定R包 如果只想更新特定的包呢?再使用一次install.packages()就行了。也可以使用devtools::update_packages()函数,这个包默认会检查指定包的依赖关系,并询问是否需要更新依赖包的版本。 packageVersion("ggplot2") #查看指定R包版本 install.packages("ggplot2") #或 devtools::update_packages() 安装R包

R包可以存放在不同的仓库(repository)里,最常见的repo包括CRAN, github,以及生物er必需的Bioconductor。

R包安装途径一:从CRAN安装。安装前建议更改镜像地址,若使用Rstudio,直接在Tools--global options--Packages里选择即可。 getOption("repo") #查看当前镜像,我把默认镜像改成了中科大的。 installed.packages() #查看已安装包 install.packages("packageName") R包安装途径二:从github安装。从GitHub上安装R包也有两种方法: 1)用devtools的install_github()函数安装。这种方法必须提供包名和对应的GitHub仓库名。 remotes::install_github("ropensci/rotl") #github仓库名/包名

2)用githubinstall包安装。

install.packages("githubinstall") library("githubinstall") install_github('packageName') R包安装途径三:从Bioconductor安装。注意用以前的source命令安装时会出现warning message: source("https://bioconductor.org/biocLite.R") Bioconductor version 3.8 (BiocInstaller 1.32.1), ?biocLite for help Warning message: 'BiocInstaller' and 'biocLite()' are deprecated, use the 'BiocManager' CRAN package instead.

因为Bioconductor在R3.5版本以后已经换用BiocManager()来安装R包啦!

install.packages("BiocManager") BiocManager::install("packageName", version = "3.2") #用双冒号起到临时加载包,而不用library(),同时可以指定使用某包中的函数。 一个更新时的警告

在安装R packagedplyr时遇到这么一个警告:

Warning message: As of rlang 0.4.0, dplyr must be at least version 0.8.0. x dplyr 0.7.8 is too old for rlang 0.4.4. i Please update dplyr to the latest version. i Updating packages on Windows requires precautions:

issue/62说的是什么呢?我好奇地打开看了看,这一看倒把我整蒙了,安装、更新包的时候必须关闭所有已加载的R对话??

Please note that on Windows, it is very important to quit or restart all R processes before upgrading , because if any R process has loaded, it will keep the .dll file open and the installer will not be able to overwrite .dll. The error message when this happens is very easy to overlook, and the new version will be partially installed: the package description and R code will be updated but the compiled code (in .dll) will not.

也就是说,如果在当前会话中某些.dll文件(动态链接库文件)已经被加载了,而你接下来要安装或更新的包刚好包含了这些.dll文件,那么这些文件将不会被修改,这可能导致包的使用出现问题。 如果想要卸载特定加载的包,可以直接用detach()指定,以Rcpp为例:

detach("package:Rcpp", unload=TRUE) #detach: remove it from the search() path of available R objects; unload=T: to attempt to unload the namespace when a package is being detached.

如果要卸载所有已加载的包,可参考https://stackoverflow.com/questions/7505547/detach-all-packages-while-working-in-r 中的回答:

lapply(names(sessionInfo()$loadedOnly), require, character.only = TRUE) invisible(lapply(paste0('package:', names(sessionInfo()$otherPkgs)), detach, character.only=TRUE, unload=TRUE, force=TRUE))

更简单的方法,在Rstudio中选择control+shift+F10,即可重启R session。

删除R包

remove.packages(pkgs, lib)

参考资料

[1] R语言包的安装 [2] 不用biocLite安装Bioconductor包 [3] R中双冒号的作用? [4] https://github.com/rstats-wtf/what-they-forgot/issues/62 [5] https://stackoverflow.com/questions/7505547/detach-all-packages-while-working-in-r [6] https://stackoverflow.com/questions/44341788/difference-between-loading-and-attaching-in-r



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3