---
disqus: ahb0222
GA : G-CQ4L16KHK4
---
# R pacman套件管理工具
> [color=#40f1ef][name=LHB阿好伯, 2020/11/12][:earth_africa:](https://www.facebook.com/LHB0222/)
###### tags: `R` `套件`

[TOC]

[:earth_asia: pacman](https://github.com/trinker/pacman)
pacman是一個R的非常好用的套件管理工具
允許使用一個函數載入一個或多個套件
以取代library()或require()函數
pacman套件中的函數名稱遵循以下格式:p_xxx“ xxx”是該函數執行的任務
下面我就介紹幾個感覺比較實用的函數
| pacman函數 | 等效功能 | 描述 |
| --- | :---: | --- |
| `p_load` | `install.packages` + `library` | 載入和安裝套件 |
| `p_install` | `install.packages` | 從CRAN安裝套件 |
| `p_load_gh` | - | 載入和安裝GitHub套件 |
| `p_install_gh` | - | 從GitHub安裝套件 |
| `p_install_version` | `install.packages` 和`packageVersion` | 安裝最低版本的套件 |
| `p_temp` | - | 安裝臨時套件 |
| `p_unload` | `detach` | 從搜索路徑中卸載套件 |
| `p_update` | `update.packages` | 更新過期套件 |
| `p_depend‵ | - |檢查套件在CRAN(默認)或本地上的依賴關係|
# p_load()-安裝,載入和更新套件
p_load()是可以安裝,載入和更新套件的通用函數
:::danger
p_load(..., char, install = TRUE, update = getOption("pac_update"), character.only = FALSE)
:::
```r=
# R code
#install.packages("pacman")
library(pacman)
p_load("ggplot2", "readxl", "dplyr", "tidyr", "DT", "reshape2", "knitr", "lubridate", "ggplot2")
```
## p_install() - 僅安裝套件
在某些時候可能只希望安裝套件
p_install()(別名為p_get())與p_load()相似但只安裝套件
:::danger
p_install(...)
:::
## GitHub安裝和加載套件
pacman為devtoolswl套件的install_github()函數提供了一個包裝器
用於安裝和加載GitHub套件
:::danger
#套件名稱格式username/repo[/subdir][@ref|#pull]
p_install_gh(c("Dasonk/githubSearch", "trinker/regexr", "hadley/httr@v0.4"))
p_load_gh("Dasonk/githubSearch", "trinker/regexr", "hadley/httr@v0.4")
:::
## p_temp() - 安裝臨時套件
p_temp()能夠安裝臨時套件
這允許只進行session-only安裝,以測試單個套件,而不會混淆原本的套件
p_temp(...)
# p_update() - 更新套件
p_update() 將自動更新套件
可以使用`p_update(FALSE)`查詢(而不是實際更新)過期的套件
# p_unload - 卸載套件
:::danger
p_unload(..., negate = FALSE, char, character.only = FALSE)
:::
## p_depends() - 檢查依賴
```r=
# R code
p_depends(ggplot2)
```
:::success
$Imports
[1] "digest" "glue" "grDevices" "grid" "gtable" "isoband" "MASS" "mgcv" "rlang"
[10] "scales" "stats" "tibble" "withr"
$Suggests
[1] "covr" "dplyr" "ggplot2movies" "hexbin" "Hmisc" "knitr" "lattice"
[8] "mapproj" "maps" "maptools" "multcomp" "munsell" "nlme" "profvis"
[15] "quantreg" "RColorBrewer" "rgeos" "rmarkdown" "rpart" "sf" "svglite"
[22] "testthat" "vdiffr"
:::
## p_information() - 回傳套件資訊
可以回傳基本套件:(a)套件,(b)版本,(c)優先級,(d)標題,(e)作者,(f)維護者,(g)說明,(h)許可,以及(i)內置
:::success
Package: ggplot2
Version: 3.3.2
Title: Create Elegant Data Visualisations Using the Grammar of Graphics
Description: A system for 'declaratively' creating graphics, based on "The Grammar of Graphics". You
provide the data, tell 'ggplot2' how to map variables to aesthetics, what graphical primitives
to use, and it takes care of the details.
.
.
.
以下省略
:::
## p_functions() - 回傳套件函數
可以回傳套件中可使用的函數列表
:::success
[1] "%+%" "%+replace%" ".data" ".pt"
[5] ".stroke" "aes" "aes_" "aes_all"
[9] "aes_auto" "aes_q" "aes_string" "after_scale"
[13] "after_stat" "alpha" "annotate" "annotation_custom"
[17] "annotation_logticks" "annotation_map"
.
.中間省略
.
[489] "sym" "syms" "theme" "theme_bw"
[493] "theme_classic" "theme_dark" "theme_get" "theme_gray"
[497] "theme_grey" "theme_light" "theme_linedraw" "theme_minimal"
[501] "theme_replace" "theme_set" "theme_test" "theme_update"
[505] "theme_void" "transform_position" "unit" "update_geom_defaults"
[509] "update_labels" "update_stat_defaults" "vars" "waiver"
[513] "wrap_dims" "xlab" "xlim" "ylab"
[517] "ylim" "zeroGrob"
:::
>參考資料
>http://trinker.github.io/pacman/vignettes/Introduction_to_pacman.html
🌟全文可以至下方連結觀看或是補充
https://hackmd.io/@LHB-0222/pacman
全文分享至
https://www.facebook.com/LHB0222/
https://www.instagram.com/ahb0222/
有疑問想討論的都歡迎於下方留言
喜歡的幫我分享給所有的朋友 \o/
有所錯誤歡迎指教
# [:page_with_curl: 全部文章列表](https://hackmd.io/@LHB-0222/AllWritings)
