Skip to content

Commit

Permalink
option to update package
Browse files Browse the repository at this point in the history
  • Loading branch information
aravindhebbali committed Jan 24, 2019
1 parent e529b2c commit 3628d0c
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
.onAttach <- function(...) {
if (!interactive() || stats::runif(1) > 0.1) return()

pkgs <- utils::available.packages()

cran_version <-
pkgs %>%
extract("xplorerr", "Version") %>%
package_version()

local_version <- utils::packageVersion("xplorerr")
behind_cran <- cran_version > local_version


tips <- c(
"Learn more about xplorerr at https://github.com/rsquaredacademy/xplorerr/.",
"Use suppressPackageStartupMessages() to eliminate package startup messages.",
Expand All @@ -9,5 +20,17 @@
)

tip <- sample(tips, 1)
packageStartupMessage(paste(strwrap(tip), collapse = "\n"))

if (interactive()) {
if (behind_cran) {
msg <- message("A new version of xplorerr is available with bug fixes and new features.")
message(msg, "\nWould you like to install it?")
if (utils::menu(c("Yes", "No")) == 1) {
utils::update.packages("xplorerr")
}
} else {
packageStartupMessage(paste(strwrap(tip), collapse = "\n"))
}
}

}

0 comments on commit 3628d0c

Please sign in to comment.