rsquaredacademy / descriptr
1
#' @importFrom utils available.packages update.packages
2
#' @importFrom stats runif
3
.onAttach <- function(...) {
4

5 1
  if (!interactive() || runif(1) > 0.1) return()
6

7 0
  pkgs          <- available.packages()
8 0
  cran_version  <- package_version(pkgs["descriptr", "Version"])
9 0
  local_version <- packageVersion("descriptr")
10 0
  behind_cran   <- cran_version > local_version
11

12 0
  tips <- c(
13 0
    "Learn more about descriptr at https://github.com/rsquaredacademy/descriptr/.",
14 0
    "Use suppressPackageStartupMessages() to eliminate package startup messages.",
15 0
    "Need help getting started with regression models? Visit: https://www.rsquaredacademy.com",
16 0
    "Check out our interactive app for quick data exploration. Visit: https://apps.rsquaredacademy.com/."
17
  )
18

19 0
  tip <- sample(tips, 1)
20

21 0
  if (interactive()) {
22 0
    if (behind_cran) {
23 0
      msg <- c("A new version of descriptr is available with bug fixes and new features.")
24 0
      packageStartupMessage(msg, "\nWould you like to install it?")
25 0
      if (menu(c("Yes", "No")) == 1) {
26 0
        update.packages("descriptr")
27
      }
28
    } else {
29 0
      packageStartupMessage(paste(strwrap(tip), collapse = "\n"))
30
    }
31
  }
32

33
}

Read our documentation on viewing source code .

Loading