Skip to content

Commit

Permalink
Replace references to MRAN with P3M
Browse files Browse the repository at this point in the history
  • Loading branch information
andrie committed Mar 27, 2024
1 parent b48d770 commit ddaf58a
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 42 deletions.
8 changes: 4 additions & 4 deletions R/MRAN.R → R/P3M.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MRAN <- function(snapshot = NULL) {
p3m <- function(snapshot = NULL) {
url <- getOption("minicran.mran")
if (missing("snapshot") || is.null(snapshot)) {
url
Expand All @@ -10,14 +10,14 @@ MRAN <- function(snapshot = NULL) {
CRAN <- function() getOption("repos")[1]


#' Returns TRUE if the MRAN URL can be accessed.
#' Returns TRUE if the p3m URL can be accessed.
#'
#' @param url MRAN url
#' @param url p3m url
#' @param tryHttp If TRUE, also attempts http URL, for compatibility with older versions of R
#'
#' @export
is.online <- function(url = NULL, tryHttp = TRUE) {
if (is.null(url)) url <- MRAN()
if (is.null(url)) url <- p3m()
url <- sub("latest$", "", url)
url <- sub("\\d{4}-\\d{2}-\\d{2}$", "", url)

Expand Down
2 changes: 1 addition & 1 deletion R/minicran-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
#'
#' @section Package options:
#'
#' \describe{ \item{\code{minicran.mran}}{preferred MRAN URL. Defaults to
#' \describe{ \item{\code{minicran.mran}}{preferred p3m URL. Defaults to
#' \url{https://mran.microsoft.com} for R versions 3.2.2 and greater. Versions
#' earlier than 3.2.2 use HTTP instead of HTTPS.} }
#'
Expand Down
4 changes: 2 additions & 2 deletions R/pkgDep.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pkgDep <- function(pkg, availPkgs, repos = getOption("repos"), type = "source",

if (missing(availPkgs)) {
if (!is.null(names(repos)) & repos["CRAN"] == "@CRAN@") {
repos <- MRAN()
repos <- p3m()
}
if (is.na(type)) type <- "source"
availPkgs <- pkgAvail(repos = repos, type = type, Rversion = Rversion,
Expand Down Expand Up @@ -169,7 +169,7 @@ pkgAvail <- function(repos = getOption("repos"),
winslash = "/"))
} else {
if (!is.null(names(repos)) && isTRUE(unname(repos["CRAN"]) == "@CRAN@")) {
repos <- MRAN()
repos <- p3m()
}
}
ap <- function() {
Expand Down
6 changes: 3 additions & 3 deletions inst/examples/example_checkVersions.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pkgTypes <- c("source", "win.binary")

if (interactive()) {
if (!is.online()) {
message("MRAN seems to be not available. Check your internet connection.")
message("p3m seems to be not available. Check your internet connection.")
} else {
pdb <- pkgAvail(repos = revolution, type = "source")
}
Expand All @@ -19,7 +19,7 @@ if (interactive()) {

if (interactive()) {
if (!is.online()) {
message("MRAN seems to be not available. Check your internet connection.")
message("p3m seems to be not available. Check your internet connection.")
} else {
pkgList <- pkgDep(pkgs, availPkgs = pdb, repos = revolution, type = "source", suggests = FALSE)
pkgList
Expand All @@ -30,7 +30,7 @@ if (interactive()) {

if (interactive()) {
if (!is.online()) {
message("MRAN seems to be not available. Check your internet connection.")
message("p3m seems to be not available. Check your internet connection.")
} else {
dir.create(pth <- file.path(tempdir(), "miniCRAN"))

Expand Down
22 changes: 11 additions & 11 deletions tests/testthat/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ hostname <- function(x) {


# Interrupt the test if url can not be reached
skip_if_offline <- function(url = MRAN()) {
skip_if_offline <- function(url = p3m()) {
# browser()
mran_host <- hostname(MRAN())
mran_host <- hostname(p3m())
if (is.null(url)) url <- mran_host
if (!is.online(url = url)) testthat::skip("offline")
}
Expand Down Expand Up @@ -93,16 +93,16 @@ mock_write_packages <- function(dir, type = "source", r_version) {
}


# Create sample repo from MRAN snapshot
.createSampleRepo <- function(MRAN, path, pkgs, Rversion = "4.0", types) {
if (missing(MRAN)) MRAN <- MRAN("2024-01-02")
# Create sample repo from p3m snapshot
.createSampleRepo <- function(p3m, path, pkgs, Rversion = "4.0", types) {
if (missing(p3m)) p3m <- p3m("2024-01-02")
if (missing(path)) path <- file.path(tempdir(), "miniCRAN", Sys.Date())
if (missing(pkgs)) pkgs <- c("chron", "curl")
if (missing(types)) types <- set_test_types()

# pdb_source <- pkgAvail(repos = MRAN, type = "source", Rversion = Rversion)
# pdb_win <- pkgAvail(repos = MRAN, type = "win.binary", Rversion = Rversion)
# pdb_mac <- pkgAvail(repos = MRAN, type = "mac.binary", Rversion = Rversion)
# pdb_source <- pkgAvail(repos = p3m, type = "source", Rversion = Rversion)
# pdb_win <- pkgAvail(repos = p3m, type = "win.binary", Rversion = Rversion)
# pdb_mac <- pkgAvail(repos = p3m, type = "mac.binary", Rversion = Rversion)

mockr::with_mock(
download_packages = mock_download_packages,
Expand All @@ -111,11 +111,11 @@ mock_write_packages <- function(dir, type = "source", r_version) {
{

for (type in types) {
pdb <- pkgAvail(repos = MRAN, type = type, Rversion = Rversion)
pkgList_source <- pkgDep(pkgs, availPkgs = pdb, repos = MRAN,
pdb <- pkgAvail(repos = p3m, type = type, Rversion = Rversion)
pkgList_source <- pkgDep(pkgs, availPkgs = pdb, repos = p3m,
type = type, suggests = FALSE, Rversion = Rversion)

makeRepo(pkgList_source, path = path, repos = MRAN,
makeRepo(pkgList_source, path = path, repos = p3m,
type = type,
quiet = TRUE, Rversion = Rversion)

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-1-pkgAvail.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ test_that("pkgAvail throws warnings and errors for incorrect CRAN repos", {
all(is.matrix(x), dim(x)[2] == 17, names(x)[1:3] == c("Package", "Version", "Priority", "Depends"))
}

skip_if_offline(MRAN())
skip_if_offline(p3m())

mran <- MRAN("2024-01-02")
mran <- p3m("2024-01-02")

expect_true(is.available.packages(
pkgAvail(repos = mran)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-2-makeDepGraph.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
checkPkgDepFunctions <- function(pkg, availPkgs = cranJuly2014,
repos = MRAN(),
repos = p3m(),
type = "source",
suggests = TRUE,
enhances = FALSE,
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-3-makeRepo.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


{
revolution <- MRAN("2023-08-31")
revolution <- p3m("2023-08-31")
if (!is.online(revolution, tryHttp = FALSE)) {
# Use http:// for older versions of R
revolution <- sub("^https://", "http://", revolution)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-4-makeRepo-from-localCRAN.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ if (interactive()) {library(testthat); Sys.setenv(NOT_CRAN = "true")}


{
revolution_mran <- MRAN("2024-01-02")
revolution_mran <- p3m("2024-01-02")
if (!is.online(revolution_mran, tryHttp = FALSE)) {
# Use http:// for older versions of R
revolution_mran <- sub("^https://", "http://", revolution_mran)
Expand Down
24 changes: 12 additions & 12 deletions tests/testthat/test-5-updateRepo.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
if (file.exists(repo_root)) unlink(repo_root, recursive = TRUE)
dir.create(repo_root, recursive = TRUE, showWarnings = FALSE)

revolution <- MRAN("2023-08-31")
revolution <- p3m("2023-08-31")
if (!is.online(revolution, tryHttp = FALSE)) {
# Use http:// for older versions of R
revolution <- sub("^https://", "http://", revolution)
Expand Down Expand Up @@ -38,7 +38,7 @@ test_that("sample repo is setup correctly", {
})
expect_type(pkgList, "list")

.createSampleRepo(path = repo_root, MRAN = revolution, Rversion = rvers,
.createSampleRepo(path = repo_root, p3m = revolution, Rversion = rvers,
pkgs = pkgs, types = names(types))
# expect_type(z, "character")
pkg_names <- unname(pkgAvail(repo_root, quiet = TRUE, type = type, Rversion = rvers)[, "Package"])
Expand Down Expand Up @@ -170,10 +170,10 @@ for (pkg_type in names(types)) {
# Check for updates -------------------------------------------------------


MRAN_mirror <- MRAN("2024-01-02")
if (!is.online(MRAN_mirror, tryHttp = FALSE)) {
p3m_mirror <- p3m("2024-01-02")
if (!is.online(p3m_mirror, tryHttp = FALSE)) {
# Use http:// for older versions of R
MRAN_mirror <- sub("^https://", "http://", revolution)
p3m_mirror <- sub("^https://", "http://", revolution)
}

pkg_type <- names(types)[1]
Expand All @@ -185,12 +185,12 @@ for (pkg_type in names(types)) {
{

skip_on_cran()
skip_if_offline(MRAN_mirror)
skip_if_offline(p3m_mirror)

prefix <- repoPrefix(pkg_type, Rversion = rvers)

old <- suppressWarnings(
oldPackages(path = repo_root, repos = MRAN_mirror,
oldPackages(path = repo_root, repos = p3m_mirror,
type = pkg_type, Rversion = rvers,
quiet = FALSE)
)
Expand All @@ -205,7 +205,7 @@ for (pkg_type in names(types)) {
write_packages = mock_write_packages,
.env = "miniCRAN",
{
updatePackages(path = repo_root, repos = MRAN_mirror, type = pkg_type,
updatePackages(path = repo_root, repos = p3m_mirror, type = pkg_type,
ask = FALSE, quiet = TRUE, Rversion = rvers)
})

Expand All @@ -226,7 +226,7 @@ for (pkg_type in names(types)) {
write_packages = mock_write_packages,
.env = "miniCRAN",
{
old <- oldPackages(path = repo_root, repos = MRAN_mirror,
old <- oldPackages(path = repo_root, repos = p3m_mirror,
type = pkg_type, Rversion = rvers)
})
# browser()
Expand All @@ -247,7 +247,7 @@ for (pkg_type in names(types)) {
{

skip_on_cran()
skip_if_offline(MRAN_mirror)
skip_if_offline(p3m_mirror)


oldVersions <- list(package = c("acepack"),
Expand All @@ -263,7 +263,7 @@ for (pkg_type in names(types)) {
{
addOldPackage(oldVersions[["package"]], path = repo_root,
vers = oldVersions[["version"]],
repos = MRAN_mirror, type = pkg_type)
repos = p3m_mirror, type = pkg_type)
})
)
} else {
Expand All @@ -274,7 +274,7 @@ for (pkg_type in names(types)) {
{
addOldPackage(oldVersions[["package"]], path = repo_root,
vers = oldVersions[["version"]],
repos = MRAN_mirror, type = pkg_type)
repos = p3m_mirror, type = pkg_type)
})
files <- suppressWarnings(
checkVersions(path = repo_root, type = pkg_type)[[pkg_type]]
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-6-getCranDescription.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test_that("can read CRAN description", {
)
}
)
p <- getCranDescription("ggplot2", repos = MRAN("2024-01-02"))
p <- getCranDescription("ggplot2", repos = p3m("2024-01-02"))
expect_s3_class(p, "data.frame")
expect_equal(p$Package[1], "ggplot2")
})
2 changes: 1 addition & 1 deletion tests/testthat/test-7-addGithubPackage.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_that("can add package from github",{
skip_on_cran()
skip_if_offline()

pdb <- pkgAvail(repos = MRAN("2024-01-02"))
pdb <- pkgAvail(repos = p3m("2024-01-02"))
expect_type(pdb, "character")

# Overwrite pdb with development version of miniCRAN at github
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-9-is-online.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ test_that("is online", {
skip_on_cran()

# Should always be TRUE, but will trigger github action failure if
# MRAN is offline
# p3m is offline
expect_true(is.online())
expect_true(is.online(MRAN("2024-01-02")))
expect_true(is.online(p3m("2024-01-02")))
})

0 comments on commit ddaf58a

Please sign in to comment.