require和library之间的主要区别在于require旨在在函数内部使用,而library用于加载包。如果包不可用,则library会抛出错误,而require会给出警告消息。使用library> library(xyz) Error in library(xyz) : there is no package called ‘xyz’使用requirerequire(xyz) Loading required package: xyz Warning message: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘xyz’在这里我们可以看到library显示错误,而require给出警告消息,因为警告大多被避免… 阅读更多