Ching-Chuan Chen's Blogger

Statistics, Machine Learning and Programming

0%

library多個套件,並自動安裝沒安裝的套件

廢話不多說,直接上code

1
2
3
4
5
6
7
8
library(pipeR)
library_mul <- function(..., lib.loc = NULL, quietly = FALSE, warn.conflicts = TRUE){
pkgs <- as.list(substitute(list(...))) %>>% sapply(as.character) %>>% setdiff("list")
if (any(!pkgs %in% installed.packages()))
install.packeges(pkgs[!pkgs %in% installed.packages()])
sapply(pkgs, library, character.only = TRUE, lib.loc = lib.loc, quietly = quietly) %>>% invisible
}
library_mul(httr, pipeR, data.table)