Skip to content

Commit

Permalink
Merge pull request #61 from dbetebenner/master
Browse files Browse the repository at this point in the history
Fixing up startup message
  • Loading branch information
dbetebenner authored Dec 5, 2024
2 parents 1c39f80 + d412a1d commit d1cc72c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Authors@R: c(person(given=c("Damian", "W."), family="Betebenner", email="dbetebe
Maintainer: Damian W. Betebenner <dbetebenner@nciea.org>
Depends: R (>= 3.3)
Suggests: knitr, rmarkdown, testthat
Imports: crayon
Imports: crayon, pkgsearch
URL: https://centerforassessment.github.io/toOrdinal/, https://github.com/centerforassessment/toOrdinal/, https://cran.r-project.org/package=toOrdinal
BugReports: https://github.com/centerforassessment/toOrdinal/issues/
VignetteBuilder: knitr
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export(toOrdinal)
export(toOrdinalDate)
importFrom(crayon,bold,green,magenta,red,yellow)
importFrom(crayon,bold,cyan,green,magenta,red,yellow)
importFrom(utils,packageVersion,tail)
45 changes: 36 additions & 9 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,47 @@
function(libname, pkgname) {
}

.onAttach <- 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("toOrdinal")
installed.version <- utils::packageDescription("toOrdinal")[['Version']]
cran.version <- tryCatch(
pkgsearch::cran_package("toOrdinal")[['Version']],
error = function(e) "Unavailable",
warning = function(w) "Unavailable")
dev.version <- get_dev_version("toOrdinal")

# Define a friendly startup message
message_text <- paste0(
magenta(bold("\uD83C\uDF89 toOrdinal v", version)), " - ", toOrdinal::toOrdinalDate("2024-12-3"), "\n",
"\U1F4A1 Tip: ", magenta(bold("> help(\"toOrdinal\")")), "\n",
"\U1F310 Docs: ", magenta(bold("https://centerforassessment.github.io/toOrdinal")), "\n",
"\u2728 Happy toOrdinaling!"
)
message_text <- paste0(
magenta(bold("\uD83C\uDF89 toOrdinal 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=\"toOrdinal\")")), "\n",
"\U1F310 Docs: ", magenta(bold("https://centerforassessment.github.io/toOrdinal")), "\n",
strrep("\u2501", 40), "\n",
"\u2728 Happy toOrdinaling!")

# Display the startup message
packageStartupMessage(message_text)
}
}
}

0 comments on commit d1cc72c

Please sign in to comment.