---
# System prepended metadata

title: 多套件安裝與更新
tags: [R]

---

---
disqus: ahb0222
GA : G-CQ4L16KHK4
---
# 多套件安裝與更新
> [color=#40f1ef][name=LHB阿好伯, 2020/02/09][:earth_africa:](https://www.facebook.com/LHB0222/)
###### tags: `R`


[TOC]

在許多時候我們在使用R的過程中會安裝或是使用多個套件
許多時候在程式碼一開始就需要有很多行`nstall.packages("XXX")`以及`library("XXX")`
例如今天分享的[文章](https://www.r-bloggers.com/an-efficient-way-to-install-and-load-r-packages/)中的情況一樣
![](https://i.imgur.com/AztVd2F.png)

在這篇文章中提到一個解決方式
先將所需套件名稱設為一向量儲存

```R=
#套件名稱
packages <- c("ggplot2", "readxl", "dplyr", "tidyr", 
    "ggfortify", "DT", "reshape2", "knitr", "lubridate", )

# 安裝尚未安裝的套件
installed_packages <- packages %in% rownames(installed.packages())
if (any(installed_packages == FALSE)) {
  install.packages(packages[!installed_packages])
}

# 載入所需套件
lapply(packages, library, character.only = TRUE) %>%
  invisible()
```



## 強制升級
update.packages(checkBuilt=TRUE, ask=FALSE)

>[An efficient way to install and load R packages](https://www.r-bloggers.com/an-efficient-way-to-install-and-load-r-packages/)
>[name=AntoineSoetewey]

# [Linux Packages for R](https://www.r-bloggers.com/2022/08/linux-packages-for-r/?utm_source=phpList&utm_medium=email&utm_campaign=R-bloggers-daily&utm_content=HTML)


```
sudo apt update

sudo apt install -q \
  libcurl4-openssl-dev \
  libssl-dev \
  libxml2-dev \
  libfontconfig1-dev \
  libharfbuzz-dev \
  libfribidi-dev \
  libfreetype6-dev \
  libpng-dev \
  libtiff5-dev \
  libjpeg-dev \
  libpq-dev
```

全文分享至

https://www.facebook.com/LHB0222/

有疑問想討論的都歡迎於下方留言

喜歡的幫我分享給所有的朋友 \o/

有所錯誤歡迎指教

![](https://i.imgur.com/47HlvGH.png)

