This is a question of convenience on code reproducibility. You may end up or receive a long code with various custom libraries called at various times (e.g. in various sections of a markdown document). Suppose you have a poorly constructed document:
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
Is there a function to possibly retrieve all these instances from the code, and store them as a list for example?
Then you could update the script to include a commented line to be used as reference for anyone working in a different workspace.
# To run this script first check if all libraries are installed and up to date.
# install.packages([results_of_an earlier_check])
Of course it is possible to find all the library functions from the script, but it would be even better to automatize this, both for framing your own scripts or updated poorly made others.