Check if R package is installed then load library

前端 未结 6 947
半阙折子戏
半阙折子戏 2020-12-15 07:49

Our R scripts are used on multiple users on multiple computers and hence there are deviations in which packages are installed on each computer. To ensure that each script wo

6条回答
  •  时光取名叫无心
    2020-12-15 08:26

    The CRAN pacman package that I maintain can address this nicely. Using the following header (to ensure pacman is installed first) and then the p_load function will try to load the package and then get them from CRAN if R can't load the package.

    if (!require("pacman")) install.packages("pacman"); library(pacman)
    p_load(qdap, ggplot2, fakePackage, dplyr, tidyr)
    

提交回复
热议问题