R 包

R 中级

Filip Schouwenaars

DataCamp Instructor

R 包

  • mean(), list(), sample() 来自哪里?
  • 它们属于 R 包
  • 包含代码、数据、文档和测试
  • 易于分享
  • 示例:baseggvis
R 中级

安装包

  • base 包:自动安装
  • ggvis 包:尚未安装

    install.packages("ggvis")
    
  • CRAN:Comprehensive R Archive Network(综合 R 归档网络)

R 中级

加载包

  • 加载包 = 附加到搜索列表
    search()
    
".GlobalEnv"  ...  "Autoloads"   "package:base"
  • 默认已附加 7 个包
  • 默认未附加 ggvis
ggvis(mtcars, ~wt, ~hp)
Error: could not find function "ggvis"
R 中级

加载包:library()

library("ggvis")
search()
".GlobalEnv"  "package:ggvis" ... "package:base"
ggvis(mtcars, ~wt, ~hp)

R 中级

加载包:require()

library("data.table")
Error in library("data.table") : 
there is no package called 'data.table'
require("data.table")
Loading required package: data.table
Warning message: ...
R 中级

加载包:require()

result <- require("data.table")
Loading required package: data.table
Warning message: ...
result
FALSE
R 中级

小结

  • 安装包:install.packages()
  • 加载包:library(), require()
  • 加载包 = 将包附加到搜索列表
  • 搜索优秀的 R 包!
R 中级

Passons à la pratique !

R 中级

Preparing Video For Download...