6

I'm currently editing an R script that was written by someone else, and a lot of packages are loaded in using library(). I've noticed that some of these packages are never used, as there are no calls to functions or methods from those particular packages. As I'm attempting to clean up the code, I wondered if there is a programmatic way to check if a package is used or not (at least one function from that package is called once)?

Green
  • 393
  • 1
  • 14
  • 2
    In R this seems like it would be a very tedious and time-consuming task. Are the `library` calls really hindering the code readability that much? What if their calls could all just be shifted to the top of the code? In terms of running the code, I don't think the presence of additional libraries makes much of a difference in speed. Try starting with this if you really need it: `library(help = ggplot2)$info[[2]]` – Gene Burinsky May 22 '17 at 23:10
  • They aren't hindering readability to a severe degree, but I asked this question to see if there was a simple way to detect unused packages so that I can remove their `library` calls. I've already moved them to the top of the code, but would still like to remove those that are unused. – Green May 22 '17 at 23:19
  • The answers are not perfect, but this question was previously asked and answered [Here](https://stackoverflow.com/questions/28513444/how-to-tell-what-packages-you-have-used-in-r) – G5W May 22 '17 at 23:59

0 Answers0