pacman
pacman copied to clipboard
Possible demo vignette
I thought a possible demonstration vignette could be nice. I'm putting this thread here to document some creative uses of pacman and if we get enough of these we could make a vignette.
I haven't thought of a vignette name if @Dasonk feels this is a good idea.
Create a .bib file of the packages you have in your library:
bib_grab <- function(x) {
m <- capture.output(p_citation(x)[[1]])
bibstart <- grepl("A BibTeX entry for LaTeX users is", m)
if(!any(bibstart)) return(NULL)
bibend <- tail(which(grepl(" }", m)), 1)
m <- substring(m[(which(bibstart)[1]+2):bibend], 3)
paste(m, collapse = "\n")
}
my_r_bibs <- sapply(p_lib(), bib_grab)
cat(paste(my_r_bibs, collapse="\n\n"), file="myR.bib")
View the package maintainers you have the most packages of in your local library
pacman::p_load(magrittr, ggplot2)
maintainers <- p_lib() %>%
lapply(p_info, fields = "Maintainer") %>%
unlist(use.names = FALSE) %>%
strsplit("\\s<") %>%
sapply("[[", 1) %>%
gsub("^'+|'+$", "", .) %>%
table() %>%
data.frame() %>%
setNames(c("Maintainer", "Count")) %>%
arrange(Count) %>%
filter(Count > 1)
maintainers[["Maintainer"]] <- factor(maintainers[["Maintainer"]],
levels=maintainers[["Maintainer"]])
ggplot(maintainers, aes(y=Maintainer, x=Count)) +
geom_point()
Network plot showing relationships between non-base package dependencies
pacman::p_load(qdapTools, igraph)
my_lib_depends <- setNames(lapply(p_lib(), function(x){
y <- p_info(x, fields=c("Depends", "Imports"))
out <- try(p_extract(y), silent = TRUE)
if (inherits(out, "try-error")) return(NULL)
out
}), p_lib())
my_lib_depends <- my_lib_depends[!sapply(my_lib_depends, is.null)]
my_lib_depends <- list2df(my_lib_depends, "dependency", "package")[, 2:1]
base <- c(p_base(TRUE), "R")
g <- graph.data.frame(my_lib_depends[
!1:nrow(my_lib_depends) %in% unique(unlist(lapply(my_lib_depends, function(x) {
which(x %in% base)
}))),])
V(g)$color <- NA
V(g)$frame.color <- NA
V(g)$label.color <- "grey80"
V(g)$label.size <- 16
E(g)$color <- "grey50"
par(bg="black", mar=rep(0, 4))
plot(g, margin=c(0, 0, 0, 0), layout=layout.circle(g))
Load non exported functions into the global environment:
setdiff(p_funs(pacman, TRUE), p_funs(pacman, FALSE))
is.loaded_package("pacman")
p_get_nonexported <- function(package, pos=1) {
invisible(lapply(setdiff(p_funs(package, TRUE, TRUE),
p_funs(package, FALSE, TRUE)), function(x) {
assign(x, eval(parse(text=paste0(package, ":::", x))), pos)
}))
}
p_get_nonexported("pacman")
is.loaded_package("pacman")