R

R에서 package 설치 확인 및 종속성있는 패키지 자동 설치하기

leebaro 2017. 11. 27.
728x90

R에서 library를 호출할 경우 설치가 안되어 있다면 install.package("package name")을 해야하는 번거로움이 있다.


이럴 때 아래와 같은 코드를 실행하면, 해당 라이브러리 뿐만 아니라 종속성이 있는 라이브러리까지 설치가 된다.


정신 건강을 위해서 이용하자.


if(!(require(pacman)) install.packages("pacman")

pacman::p_load(data.table, dplyr, ggplot2)



아래 코드를 사용해도 설치된 라이브러리를 확인할 수 있다.


list.of.packages <- c("ggplot2", "Rcpp")

new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]

if(length(new.packages)) install.packages(new.packages)




Reference


https://stackoverflow.com/questions/4090169/elegant-way-to-check-for-missing-packages-and-install-them

http://code.i-harness.com/ko/docs/r/6b7

728x90