Home > front end >  Why does loading multiple packages in R produce warnings?
Why does loading multiple packages in R produce warnings?

Time:12-28

required_packs <- c("pdftools","readxl","pdfsearch","tidyverse","data.table","stringr","tidytext","dplyr","igraph","NLP","tm", "quanteda", "ggraph", "topicmodels", "lasso2", "reshape2", "FSelector")
new_packs <- required_packs[!(required_packs %in% installed.packages()[,"Package"])]
if(length(new_packs)) install.packages(new_packs)
i <- 1
for (i in 1:length(required_packs)) {
 sapply(required_packs[i],require, character.only = T)
}

Produces a warning for each new package. I have tried sapply outside a loop as well and the same warnings appear.

Warning in if (!character.only) package <- as.character(substitute(package)) :
  the condition has length > 1 and only the first element will be used

CodePudding user response:

I think the problem is that you used T when you meant TRUE. For example,

    T <- 1:10
    require("stats", character.only = T)
#> Warning in if (!character.only) package <- as.character(substitute(package)):
#> the condition has length > 1 and only the first element will be used

Created on 2021-12-27 by the reprex package (v2.0.1)

Remember, T is a variable name in R. You can change its value. It is frequently a source of obscure bugs when you use it instead of the constant value TRUE.

  •  Tags:  
  • r
  • Related