R 패키지 설치 여부 체크 후, 필요시 설치 후 라이브러리 불러들이기

2020. 6. 13. 15:36분석 R/구현

728x90

 

  1. packages 있는지 없는지 체크
  2. packages 체크 후에 설치하기
  3. packages 설치하고 라이브러리 불러들이기
list.of.packages <- c("doBy","dplyr")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]

if(length(new.packages)){
  install.packages(new.packages)
  lapply(list.of.packages, require ,  
         character.only = TRUE)
} else{
  print("설치할 패키지(x) 패키지 로딩")
  lapply(list.of.packages, require ,  
         character.only = TRUE)
}

 

728x90