Can we create a list of downloaded packages in R?
Thank you for not being vague. Since you mentioned duplicate environments, there is information about the availability and namespaces of these available packages here.
In addition to the functions specified by @smci, will .Packages
list all packages available in the path to the library folder lib.loc
. And find.package
will show you the path to the package. Be aware of what find.packages
can be problematic when determining the availability of a package. require
- recommended method (see ?find.package
for explanation).
> x <- .packages(TRUE)
> head(x)
# [1] "assertthat" "BH" "car" "data.table"
# [5] "digest" "dplyr"
> f <- find.package(x)
> sample(f, 5)
# [1] "/home/richard/R/x86_64-pc-linux-gnu-library/3.1/latticeExtra"
# [2] "/home/richard/R/x86_64-pc-linux-gnu-library/3.1/Lahman"
# [3] "/home/richard/R/x86_64-pc-linux-gnu-library/3.1/microbenchmark"
# [4] "/usr/lib/R/library/tools"
# [5] "/home/richard/R/x86_64-pc-linux-gnu-library/3.1/knitr"
For a list of environments with namespaces for these packages in, x
you can use (among others)getNamespace
> sapply(x, getNamespace)[1:3]
# $assertthat
# <environment: namespace:assertthat>
# $BH
# <environment: namespace:BH>
# $car
# <environment: namespace:car>
source to share
If you meant " after running the appropriate code ":
-
loadedNamespaces()
(package names only or) -
search()
as @Richard Scriven said
but if you meant to statically parse the given code without running it , there is no tool, but outputting the results from egrep -R -w '(require|include|source)' *.r
should give you what you want (obviously, but not used or commented out)
source to share