这是代码再现性的方便问题。您最终可能会收到或收到一个长代码,其中包含在不同时间调用的各种自定义库(例如,在降价文档的各个部分中)。假设您有一个结构不佳的文档:
library(ggplot2)
# lots of lines of code
# and then more packages invoked, using both commands just spice things up
require(igraph)
# lots of lines of code
library(pracma)
# lots of lines of code
# etc
是否有一个函数可以从代码中检索所有这些实例,并将它们存储为例如列表?
然后,您可以更新脚本以包含注释行,以供在不同工作区工作的任何人参考。
# To run this script first check if all libraries are installed and up to date.
# install.packages([results_of_an earlier_check])
当然,可以从脚本中找到所有的库函数,但是自动化它会更好,无论是为了构建自己的脚本还是更新制作不佳的其他脚本。