Skip to content

Commit

Permalink
Tweak tidyverse_attach
Browse files Browse the repository at this point in the history
* Use two columns
* Eliminate session info
  • Loading branch information
hadley committed Nov 6, 2017
1 parent c704b28 commit 25a131f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 48 deletions.
7 changes: 3 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
* Added reprex to the tidyverse (#47)

* On attach, tidyverse now makes better use of the horizontal space,
printing package versions and some useful info about your session (#59).
It's now more valuable inside reprexes or committed in rendered RMarkdown
documents.

printing packages and versions in two columns (#59). Development
versions are highlighted in red.

I've also tweaked the display of conflicts to hopefully make it more
clear which function is the "winner".

Expand Down
49 changes: 5 additions & 44 deletions R/attach.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tidyverse_attach <- function() {
msg(
cli::rule(
left = crayon::bold("Attaching packages"),
right = paste0("tidyverse ", utils::packageVersion("tidyverse"))
right = paste0("tidyverse ", package_version("tidyverse"))
),
startup = TRUE
)
Expand All @@ -14,62 +14,23 @@ tidyverse_attach <- function() {
crayon::col_align(versions, max(crayon::col_nchar(versions)))
)

info <- platform_info()
info_name <- paste0(format(names(info), justify = "right"), ": ")
info <- paste0(style_grey(0.6, info_name), style_grey(0.4, info))
col1 <- 1:floor(length(packages)/2)
info <- paste0(packages[col1], " ", packages[-col1])

n <- max(length(packages), length(info))
info <- c(info, rep("", n - length(info)))
msg(paste(info, collapse = "\n"), startup = TRUE)

info <- paste0(packages, " ", info, collapse = "\n")

msg(info, startup = TRUE)
suppressPackageStartupMessages(
lapply(core, library, character.only = TRUE, warn.conflicts = FALSE)
)

invisible()
}


package_version <- function(x) {
version <- as.character(unclass(utils::packageVersion(x))[[1]])

if (length(version) > 3) {
version[4:length(version)] <- crayon::bgRed(crayon::white(as.character(version[4:length(version)])))
version[4:length(version)] <- crayon::red(as.character(version[4:length(version)]))
}
paste0(version, collapse = ".")
}


platform_info <- function() {
if (rstudioapi::isAvailable()) {
ver <- rstudioapi::getVersion()
ui <- paste0("RStudio ", ver, "")
} else {
ui <- .Platform$GUI
}

ver <- R.version

c(
Date = format(Sys.Date()),
R = paste0(ver$major, ".", ver$minor),
OS = os(),
GUI = ui,
Locale = Sys.getlocale("LC_COLLATE"),
TZ = Sys.timezone()
)
}

os <- function() {
x <- utils::sessionInfo()$running

# Regexps to clean up long windows strings generated at
# https://github.com/wch/r-source/blob/af7f52f70101960861e5d995d3a4bec010bc89e6/src/library/utils/src/windows/util.c

x <- gsub("Service Pack", "SP", x)
x <- gsub(" [(]build \\d+[)]", "", x)

x
}

0 comments on commit 25a131f

Please sign in to comment.