1
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
Matt Dietz
  • 37
  • 5
  • I don't get those warnings. Could you post the result of `sessionInfo()`? If you're getting the warning without `sapply`, maybe you should also post the simplest reproducible example you can put together. – user2554330 Dec 27 '21 at 16:34
  • Side notes: (1) no need to pre-instantiate `i – r2evans Dec 27 '21 at 16:39

1 Answers1

0

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.

user2554330
  • 30,741
  • 4
  • 34
  • 76