R语言-包的一些操作命令
R包的安装路径相关
# R官网相关
https://www.r-project.org/
https://cran.r-project.org/
https://r-forge.r-project.org/R/?group_id=156
https://cran.rstudio.com/src/contrib/packages
# R镜像相关
https://cran.r-project.org/mirrors.html
Name,Country,City,URL,Host,Maintainer,OK,CountryCode,Comment
"0-Cloud [https]",0-Cloud,0-Cloud,https://cran.rstudio.com/,"Rstudio, automatic redirection to servers worldwide","winston # stdout.org",1,us,"secure_mirror_from_master"
"0-Cloud",0-Cloud,0-Cloud,http://cran.rstudio.com/,"Rstudio, automatic redirection to servers worldwide","winston # stdout.org",1,us,"secure_mirror_from_master"
"China (Beijing 2)",China,Bejing,http://mirror.bjtu.edu.cn/cran/,"Beijing Jiaotong University, Beijing","idealities # gmail.com",1,cn
"China (Beijing 3)",China,Beijing,http://mirrors.opencas.cn/cran/,"Chinese Academy of Sciences, Beijing","admin # opencas.cn",1,cn
"China (Beijing 4) [https]",China,Beijing,https://mirrors.tuna.tsinghua.edu.cn/CRAN/,"TUNA Team, Tsinghua University","Justin Wong <justin.w.xd # gmail.com>",1,cn
"China (Beijing 4)",China,Beijing,http://mirrors.tuna.tsinghua.edu.cn/CRAN/,"TUNA Team, Tsinghua University","Justin Wong <justin.w.xd # gmail.com>",1,cn
"China (Hefei) [https]",China,Hefei,https://mirrors.ustc.edu.cn/CRAN/,"University of Science and Technology of China","mirrors # Ustc.edu.cn",0,cn
"China (Hefei)",China,Hefei,http://mirrors.ustc.edu.cn/CRAN/,"University of Science and Technology of China","mirrors # Ustc.edu.cn",0,cn
"China (Xiamen)",China,Xiamen,http://mirrors.xmu.edu.cn/CRAN/,"Xiamen University","admin # Xdmc.org",1,cn,"maintainer_address_bounces"
# R包安装相关
?install.packages()
# 如:install.packages("mypackage",repos="http://mirrors.tuna.tsinghua.edu.cn/CRAN/")
# R包网址下载
https://cran.r-project.org/web/packages/packages/index.html
https://cran.r-project.org/web/packages/sp/index.html
https://cran.rstudio.com/src/contrib/RCurl_1.95-4.8.tar.gz
R环境和包操作相关命令
查询用户HOME地址
Sys.getenv("HOME")
查询R HOME安装地址
Sys.getenv("R_HOME")
查看包的安装目录\设置包的安装目录
.libPaths() \ .libPaths('path')
查看已经安装的包目录
library()
载入mypackage包\删除载入的包
library(mypackage)
require(dplyr)
detach(dplyr)
包的载入library()或require(),安装完包后,需要加载才能使用其中的函数,此时括号中不使用引号。两者的不同之处在于library()载入之后不返回任何信息,而require()载入后则会返回TRUE,因此require()适合用于程序的书写。例如:
library(ggplto2)
> require(foreign)
Loading required package: foreign
> is.logical(require(foreign))
[1] TRUE
卸载包detach(),这是library()的反向操作,此操作主要是为了避免某些包中的函数名称相同,造成冲突,注意与library()的参数不同,detach()参数为detach(package:包的名称),library(包的名称)。例如:
> library(ggplot2) # 加载包
> (.packages()) # 列出当前已经加载的包
[1] "ggplot2" "stats" "graphics" "grDevices" "utils" "datasets" "methods" "base"
> detach(package:ggplot2) # 卸载ggplot2包
> (.packages()) # 列出当前已经加载的包
[1] "stats" "graphics" "grDevices" "utils" "datasets" "methods" "base"
查看启动R时自动载入的包
getOption("defaultPackages")
查看当前载入的包
search()
查看R中载入的包
sessionInfo()
查看已安装包信息
installed.packages()
查看当前已经加载过的R包:
(.packages())
查看全部安装的R包:
.packages(all.available=TRUE)
.packages(all.available=T)
查看某个R包是否已经安装:
library("XML")
查看某个安装的R包:
help(package="XML")
卸载package | 如何卸载已安装的packages
remove.packages("mypackage")
remove.packages(c("pkg1","pkg2"),lib = file.path("path","to","library"))
查看R及其package的version
# R version: version
R.version
# R package version:
library(help='XML')
packageVersion('XML')
升级R,不重装packages
拷贝原library目录下文件到新library目录下
更新包 | 可以定期执行以下
update.packages()
查看"mypackage"的帮助
help(package = 'mypackage')
查看已经安装包的详细HTML文档
help.start()
查看function(先载入包)
# 查看函数的参数
args(function)
# 自动运行该函数帮助文档中的例子
example(function)
查询包内信息(先载入包)
# 查看某个“函数”或者“方法”的详细内容
?function/method
# 查看"mypackage"中的所有对象
ls("package:mypackage")
查看某个S3泛型函数中所有的方法或者一个类中所有的方法(S3:S version 3)
methods()
查看S4类的方法
showMethods(class = "myClass")
WIN环境下设置环境变量R_LIBS将R包安装到自定义路径
R离线下载R包和依赖
在离线状态下,为了更方便安装R包,可以用以下方式:
# 下载包和依赖到本地目录下
# download
getPackages <- function(packs){
packages <- unlist(
tools::package_dependencies(packs, available.packages(),which=c("Depends", "Imports"), recursive=TRUE)
)
packages <- union(packs, packages)
packages
}
myPackages <- c("dplyr","sqldf","DBI","rJava","RJDBC","forecast","lubridate","xgboost","ggplot2","plyr")
packages <- getPackages(myPackages)
download.packages(packages, destdir="D:/Rpackages/", type="source")
# 把包和依赖传入离线环境后,离线安装:
# install
library(tools)
path <- "D:/Rpackages"
write_PACKAGES(path,type="source")
myPackages <- c("dplyr","sqldf","DBI","rJava","RJDBC","forecast","lubridate","xgboost","ggplot2","plyr")
install.packages(myPackages, contriburl=paste("file:",path,sep=''),type="source")
R常用软件包安装
# 1.在R的控制台,输入
install.packages("servr") # 安装 servr
install.packages("servr", contriburl="http://www.your.url", dependencies = TRUE) # 安装 servr
# 2.若要指定安装目录 (e.g. “mydir”),则输入
install.packages("stepNorm", contriburl="http://www.biostat.ucsf.edu/jean/software", lib="mydir")
install.packages('servr') # stable version; use a CRAN mirror, or
install.packages('servr', repos='http://yihui.name/xran') # devel version
# 3.在Github上直接安装R包步骤
一、安装devtools包
install.packages("devtools")
library(devtools)
二、安装github上的R包
devtools::install_github('lchiffon/REmap')
library(REmap)
################
install.packages("sciplot")
install.packages("lattice")
install.packages("plotrix")
install.packages("IDPmisc")
install.packages("RODBC")
install.packages("lubridate")
install.packages("robustbase")
install.packages("robust")
install.packages("R.matlab")
install.packages("qualityTools")
install.packages("xlsx")
install.packages("rgl")
install.packages("evd")
install.packages("pheatmap")
install.packages("rvest") ##抓取网页数据
install.packages("stringr") ##处理文本
install.packages("zoo")
install.packages("ggplot2")
install.packages("quantmod")
install.packages("plyr")
install.packages("reshape2")
install.packages("nnet")
install.packages("sound")
install.packages("fmsb")
install.packages("XML")
install.packages("e1071")
install.packages("fields")
install.packages("spam")
install.packages("sqldf")
install.packages("dplyr")
install.packages("scatterplot3d")
install.packages("chron")
install.packages("downloader")
install.packages("RCurl")
install.packages("googleVis")
install.packages("pracma")
install.packages("Cairo")
install.packages("Rcpp")
install.packages("magrittr")
install.packages("data.table")
install.packages("AlgDesign")
install.packages("R6")
install.packages("igraph")
install.packages("car") ## where data Prestige is
install.packages("gtable")
install.packages("bmp")
install.packages("pixmap")
install.packages("showtext")
install.packages("ape")
install.packages("RUnit")
install.packages("jpeg")
install.packages("png")
install.packages("gWidgets2")
install.packages("gWidgetsRGtk2")
install.packages("gWidgets")
install.packages("tcltk2")
install.packages("emdbook")
install.packages("bc")
install.packages("rClr")
install.packages("sos")
install.packages("Rmpfr")
install.packages("mosaic")
install.packages("wordcloud")
install.packages("stringi")
install.packages("gsubfn")
install.packages("microbenchmark")
install.packages("magic")
install.packages("gridExtra")
install.packages("kohonen")
install.packages("venneuler")
install.packages("rjava")
install.packages("mvnormtest")
install.packages("vars")
install.packages("optparse")
install.packages("getopt")
install.packages("expm")
install.packages('shiny')
install.packages('shinyapp')
install.packages('DBI')
install.packages('RPostgreSQL') #Linux下需要加载yum源插件---yum -y install postgresql-devel
install.packages("MASS")
################
©哈尔滨商业大学 银河统计工作室
银河统计工作室成员由在校统计、计算机部分师生和企业数据数据分析师组成,维护和开发银河统计网和银河统计博客(技术文档)。专注于数据挖掘技术研究和运用,探索统计学、应用数学和IT技术有机结合,尝试大数据条件下新型统计学教学模式。
邮箱:wanglei@hrbcu.edu.cn 关于我们