• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

R语言-包的一些操作命令

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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")
################

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
R语言 查看已加载包、卸除加载包 及安装包与卸载包发布时间:2022-07-18
下一篇:
R语言下载函数download.file()发布时间:2022-07-18
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap