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)
}
为每个新程序包生成一个警告。我也尝试过巧妙地跳出一个循环,同样的警告也出现了。
Warning in if (!character.only) package <- as.character(substitute(package)) :
the condition has length > 1 and only the first element will be used
我认为问题在于,当你指的是TRUE
时,你使用了T
。例如,
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
创建于2021-12-27由reprex包(v2.0.1(
请记住,T
是R中的一个变量名。您可以更改其值。当您使用它而不是常数值TRUE
时,它经常是模糊错误的来源。