I am the author of a package storred on github. My colleagues install this package with devtools::install_github()
. They would like to test if the package has been updated or not. Is there a function to check that there has been a commit to the github master branch since they last installed the package?
This is an indirect approach I am aware of
You can then find your installed version by packageVersion()
There's a package available which goes by the name versions
.
The function available.versions()
could help you.
This will find you all the package versions ever available.
packageVersion("ggplot2")
#[1] ‘1.0.1’
available.versions("ggplot2")
#$ggplot2
# version date available
#1 1.0.1 2015-03-17 TRUE
#2 1.0.0 2014-05-21 FALSE
#3 0.9.3.1 2013-03-02 FALSE
...
Update:
Package devtools has functions package_deps() and dev_package_deps().
package_deps("ggplot2")
# Needs update -----------------------------
# package installed available
# ggplot2 2.0.0 2.1.0
# scales NA 0.4.0
?package_deps
"Find all dependencies of a CRAN or dev package."
{This function is untested for development package from my end . However I believe this should do your job.}
repo
argument of dev_package_deps()
for a github repos? For example for ggplot2. –
Carport package_deps("rNVD3", repos = "ramnathv/rNVD3")
–
Supercolumnar package_deps("ggplot2", repos = "hadley/ggplot2")
doesn't check the "hadley/ggplot2"
repository on github, it just returns "Not on CRAN ----"
. While package_deps("ggplot2")
tells me the package that need to be updated based on information available on CRAN. What's unclear to me in ?dev_package_deps
is what does a "dev" package mean? I guess it's a package you are developing on your system, not a package hosted on github. –
Carport package_deps()
is part of the package remotes
–
Fula Having the same problem, I created this function, getting inspired by devtools::install_github
, that does the job for me. As I understand it it compares the SHA of the installed package and the one on github. I think it requires that the package is installed using devtools::install_github, but haven't tested it extensively enough.
check_github_sha <- function(username, repo, host = "api.github.com") {
if (Sys.getenv("GITHUB_PAT") == "") {
stop('Make sure that you have set a "Personal Acess Token" (PAT) named GITHUB_PAT in .Renviron')
}
remote_obj <- remote <- list(
host = host,
package = NULL,
repo = repo,
subdir = NULL,
username = username,
ref = "HEAD",
sha = NULL,
auth_token = Sys.getenv("GITHUB_PAT")
)
remote_obj <- structure(remote_obj, format = format, class = c("github_remote", "remote"))
remote_sha <- remotes::remote_sha(remote_obj)
local_sha <- utils::packageDescription(repo, lib.loc = .libPaths())
if(!"GithubSHA1" %in% names(local_sha)){
cat(paste0("\033[0;", 33, "m", paste0(repo, "is not installed from github. Probably using build in Rstudio or similar"), "\033[0m", "\n"))
} else {
if (remote_sha != local_sha["GithubSHA1"]) {
cat(paste0("\033[0;", 31, "m", paste0("NOTE: there is a new version of ", repo, " available"), "\033[0m", "\n"))
} else {
cat(paste0("\033[0;", 32, "m", paste0("you have the latest version of ", repo), "\033[0m", "\n"))
}
}
}
check_github_sha(username = "username", repo = "repo")
© 2022 - 2025 — McMap. All rights reserved.
versions::available.versions()
will "list all of the past versions of the named packages ever uploaded to CRAN". So this will not work with package installed from Github. – Carport