在miniCRAN :: pkgAvail调用available.packages中找不到contribUrl函数的源代码

时间:2016-08-10 02:29:52

标签: r

miniCRAN包的pkgAvail函数基本上是available.packages函数的包装器。我遇到的问题是在repo参数中找到contribUrl()函数调用的定义。 我理解它应该做什么 - 允许显式标识R版本的contrib url,而不是使用R.version。 但是contribUrl()定义在哪里?

available.packages
        utils::available.packages(contribUrl(repos, type = type, 
            Rversion = Rversion), type = type, filters = list())

对于上下文,这是函数调用来自的地方:

pkgAvail <- function (repos = getOption("repos"), type = "source", Rversion = R.version) 
{
    if (!grepl("^http://|file:///", repos[1]) && file.exists(repos[1])) {
        repos <- paste0("file:///", normalizePath(repos[1], mustWork = FALSE, 
            winslash = "/"))
    }
    else {
        if (!is.null(names(repos)) && isTRUE(unname(repos["CRAN"]) == 
            "@CRAN@")) {
            repos <- MRAN()
        }
    }
    utils::available.packages(contribUrl(repos, type = type, 
        Rversion = Rversion), type = type, filters = list())
}

1 个答案:

答案 0 :(得分:0)

这是namelist /.../ ...,...,... contrib.url的修改后的副本。它在这里定义:

https://github.com/RevolutionAnalytics/miniCRAN/blob/master/R/pkgDep.R

这是定义:

utils

这是原始功能:

# Modified copy of utils::contrib.url()
contribUrl <- function (repos, type = getOption("pkgType"), Rversion = R.version) {
  Rversion <- twodigitRversion(Rversion)
  if (type == "both") 
    type <- "source"
  if (type == "binary") 
    type <- .Platform$pkgType
  if (is.null(repos)) 
    return(NULL)
  if ("@CRAN@" %in% repos && interactive()) {
    cat(gettext("--- Please select a CRAN mirror for use in this session ---"), 
        "\n", sep = "")
    flush.console()
    chooseCRANmirror()
    m <- match("@CRAN@", repos)
    nm <- names(repos)
    repos[m] <- getOption("repos")["CRAN"]
    if (is.null(nm)) 
      nm <- rep("", length(repos))
    nm[m] <- "CRAN"
    names(repos) <- nm
  }
  if ("@CRAN@" %in% repos) 
    stop("trying to use CRAN without setting a mirror")
  ver <- Rversion
  mac.path <- "macosx"
  if (substr(type, 1L, 11L) == "mac.binary.") {
    mac.path <- paste(mac.path, substring(type, 12L), sep = "/")
    type <- "mac.binary"
  }
  res <- switch(type, 
                source = paste(gsub("/$", "", repos), "src", "contrib", sep = "/"), 
                mac.binary = paste(gsub("/$", "", repos), "bin", mac.path, "contrib", ver, sep = "/"), 
                win.binary = paste(gsub("/$", "", repos), "bin", "windows", "contrib", ver, sep = "/"))
  res
}