Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Imports:
Remotes:
github::PHSKC-APDE/rads, github::PHSKC-APDE/dtsurvey
Suggests:
devtools,
httr,
keyring,
knitr,
Expand Down
41 changes: 41 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.onAttach <- function(libname, pkgname) {
tryCatch({
if (!requireNamespace("httr", quietly = TRUE)) {
packageStartupMessage("apde.chi.tools update check skipped: \n'httr' package is needed to check for updates and is not installed.")
return()
}

url <- "https://raw.githubusercontent.com/PHSKC-APDE/apde.chi.tools/main/DESCRIPTION"
resp <- httr::GET(url)

if (httr::status_code(resp) == 200) { # 200 means is okay / was successful
desc_text <- httr::content(resp, "text")

# use Debian Control Format (.dcf) because the DESCRIPTION file in R uses dcf
desc_vals <- tryCatch(read.dcf(textConnection(desc_text)), error = function(e) NULL)

remote_version <- NULL
if (!is.null(desc_vals) && "Version" %in% colnames(desc_vals)) {
remote_version <- package_version(desc_vals[1, "Version"])
}

local_version <- utils::packageVersion(pkgname)

if (!is.null(remote_version) && remote_version > local_version) {
packageStartupMessage("-----------------------------------------------------")
packageStartupMessage("\u26A0\ufe0f A newer version of apde.chi.tools is available: ", remote_version)
packageStartupMessage("Your version: ", local_version)
update_msg <- ifelse(requireNamespace("devtools", quietly = TRUE),
'\U0001f504 To update, run: devtools::install_github("PHSKC-APDE/apde.chi.tools", auth_token = NULL)',
'\U0001f504 To update, install devtools and then run: devtools::install_github("PHSKC-APDE/apde.chi.tools", auth_token = NULL)'
)
packageStartupMessage(update_msg)
packageStartupMessage("-----------------------------------------------------")
}
} else {
packageStartupMessage("Could not retrieve version info from GitHub (status: ", httr::status_code(resp), ")")
}
}, error = function(e) {
packageStartupMessage("Version check skipped: could not connect to GitHub")
})
}