Skip to content

Commit

Permalink
Update of startup message
Browse files Browse the repository at this point in the history
  • Loading branch information
dbetebenner committed Dec 5, 2024
1 parent 06d09d5 commit d3871c7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
importFrom(crayon,bold,green,magenta,red,yellow)
importFrom(crayon,bold,cyan,green,magenta,red,yellow)
importFrom(utils,packageVersion)
importFrom(toOrdinal,toOrdinal)
import(data.table)
41 changes: 34 additions & 7 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,43 @@ function(libname, pkgname) {

`.onAttach` <- function(libname, pkgname) {
if (interactive()) {
# Utility function
get_dev_version <- function(package) {
url <- paste0("https://raw.githubusercontent.com/CenterForAssessment/", package, "/refs/heads/master/DESCRIPTION")
tryCatch({
lines <- readLines(url, warn = FALSE)
version_line <- grep("^Version:", lines, value = TRUE)
if (length(version_line) > 0) {
return(strsplit(version_line, ": ")[[1]][2])
} else {
return("Unavailable")
}
}, error = function(e) {
return("Unavailable")
}, warning = function(w) {
return("Unavailable")
})
}

# Extract version information
version <- utils::packageVersion("SGPdata")
installed.version <- utils::packageDescription("SGPdata")[['Version']]
cran.version <- tryCatch(
pkgsearch::cran_package("SGPdata")[['Version']],
error = function(e) "Unavailable",
warning = function(w) "Unavailable")
dev.version <- get_dev_version("SGPdata")

# Define a friendly startup message
message_text <- paste0(
magenta(bold("\uD83C\uDF89 SGPdata v", version)), " - ", toOrdinal::toOrdinalDate("2024-12-3"), "\n",
"\U1F4A1 Tip: ", magenta(bold("> help(\"SGPdata\")")), "\n",
"\U1F310 Docs: ", magenta(bold("https://centerforassessment.github.io/SGPdata")), "\n",
"\u2728 Happy SGPing!"
)
message_text <- paste0(
magenta(bold("\uD83C\uDF89 SGPdata v", installed.version, sep="")), " - ", toOrdinal::toOrdinalDate("2024-12-4"), "\n",
strrep("\u2501", 40), "\n",
bold("\U1F4E6 CRAN: "), green("v", cran.version, sep=""), "\n",
bold("\U1F527 Dev: "), cyan("v", dev.version, sep=""), "\n",
strrep("\u2501", 40), "\n",
"\U1F4A1 Tip: ", magenta(bold("> help(package=\"SGPdata\")")), "\n",
"\U1F310 Docs: ", magenta(bold("https://centerforassessment.github.io/SGPdata")), "\n",
strrep("\u2501", 40), "\n",
"\u2728 Happy SGPing!")

# Display the startup message
packageStartupMessage(message_text)
Expand Down

0 comments on commit d3871c7

Please sign in to comment.