Skip to content

Instantly share code, notes, and snippets.

View BrianDiggs's full-sized avatar

Brian Diggs BrianDiggs

View GitHub Profile
@BrianDiggs
BrianDiggs / IdentifyUnusedPackages.R
Last active July 7, 2023 18:47
A script which should find packages which you have loaded which are not used in a script. It needs to be run in a clean session because there is no way to verify that the state of your current session is the same as what the script would create. It assumes that packages are only loaded with either library or require, which is good practice anywa…
# Define the file to test in the line below. That is the only per-run configuration needed.
fileToTest <- "Plot.R"
# Get the parse data for the file
parseData <- getParseData(parse(fileToTest), includeText = TRUE)
# Extract all the function calls and keep a unique list of them.
functionCalls <- unique(parseData[parseData$token == "SYMBOL_FUNCTION_CALL", "text"])
# Look for any calls to `library` or `require` and go two steps up the
@BrianDiggs
BrianDiggs / mytestscript.r
Created December 13, 2012 23:57
git bisect script used to find where the ordering problem was introduced for tidyverse/ggplot2#721
## To run this script:
## git bisect reset
## git bisect start ggplot2-0.9.2.1 f4faab0
## git bisect run "C:\Program Files\R\R-2.15.2\bin\R" -f mytestscript.r
cat("\n===== Running test script ======\n")
library("bisectr")
library("digest")
library("methods")