为什么在R中加载多个包会产生警告

  • 本文关键字:包会产 警告 加载 r
  • 更新时间 :
  • 英文 :

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时,它经常是模糊错误的来源。

最新更新