Created
November 11, 2023 11:32
-
-
Save vjcitn/8959e01892df2cd5376ec8b8b63eaf73 to your computer and use it in GitHub Desktop.
a redefinition of library() to be quieter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# a replacement for library() that does not print tons of messages | |
# as each package is loaded. place in .Rprofile | |
libstats = function(inisess, newsess) { | |
inibase = inisess$basePkgs # unchanging? | |
inioth = names(inisess$otherPkgs) | |
newbase = newsess$basePkgs | |
newoth = names(newsess$otherPkgs) | |
iniatt = length(unique(c(inibase,inioth))) | |
newatt = length(unique(c(newbase,newoth))) | |
addatt = newatt-iniatt | |
inilo = names(inisess$loadedOnly) | |
newlo = names(newsess$loadedOnly) | |
addlo = length(setdiff(newlo, inilo)) | |
c(addatt=addatt, addlo=addlo) | |
} | |
library = function(...) { | |
libstats = function(inisess, newsess) { | |
inibase = inisess$basePkgs # unchanging? | |
inioth = names(inisess$otherPkgs) | |
newbase = newsess$basePkgs | |
newoth = names(newsess$otherPkgs) | |
iniatt = length(unique(c(inibase,inioth))) | |
newatt = length(unique(c(newbase,newoth))) | |
addatt = newatt-iniatt | |
inilo = names(inisess$loadedOnly) | |
newlo = names(newsess$loadedOnly) | |
addlo = length(setdiff(newlo, inilo)) | |
c(addatt=addatt, addlo=addlo) | |
} | |
inisess = utils::sessionInfo() | |
suppressPackageStartupMessages({ | |
libdata = base::library(...) | |
newsess = utils::sessionInfo() | |
lstats = libstats(inisess=inisess, newsess=newsess) | |
message(sprintf("%d/%d packages newly attached/loaded, see sessionInfo() for details.", lstats["addatt"], | |
lstats["addlo"])) | |
invisible(NULL) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment