LHB阿好伯, 2020/11/12
Image Not Showing Possible ReasonsLearn More →
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
R
套件
Learn More →
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(…, char, install = TRUE, update = getOption("pac_update"), character.only = FALSE)
在某些時候可能只希望安裝套件
p_install()(別名為p_get())與p_load()相似但只安裝套件
p_install(…)
pacman為devtoolswl套件的install_github()函數提供了一個包裝器
用於安裝和加載GitHub套件
#套件名稱格式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()能夠安裝臨時套件
這允許只進行session-only安裝,以測試單個套件,而不會混淆原本的套件
p_temp(…)
p_update() 將自動更新套件
可以使用p_update(FALSE)
查詢(而不是實際更新)過期的套件
p_unload(…, negate = FALSE, char, character.only = FALSE)
$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"
可以回傳基本套件:(a)套件,(b)版本,(c)優先級,(d)標題,(e)作者,(f)維護者,(g)說明,(h)許可,以及(i)內置
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.
.
.
.
以下省略
可以回傳套件中可使用的函數列表
[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/
有所錯誤歡迎指教