/usr/lib/R/site-library/Biobase/scripts/query.packages.R is in r-bioc-biobase 2.14.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | # This function queries the repository for packages and finds the urls
# for all the packages a given package depends on. The urls will be
# returned as list that contains the repository, url, and version
# number of the package and a list of the urls for all the packages the
# package depends on.
#
# pkgName: a character string for the name of the package whose
# dependency will be queried.
# pkgVersion: a integer for the version number of the packages on
# which a given package depends. Default is to get the largest versin
# number.
# type: a character string for the type of the package. Should be
# either "unix" or "windows".
# repositories: a list of urls for the respositories to be
# searched. The default is bioconductor and then CRAN.
#
query.packages <- function (pkgName, pkgVersion = NULL, type = "unix",
repositories = getDefaultRep(bioCOnly = FALSE)){
on.exit(options(show.error.messages = TRUE))
pkgFound <- FALSE
collectedItem <- NULL
pkgPat <- getPkgPat(pkgName)
returnList <- list(repository = NULL,
packUrl = NULL,
version = ifelse(is.null(pkgVersion), -1, pkgVersion),
type = ifelse(is.null(type), .Platform$OS.type, type),
depends = NULL)
tempRep <- NULL
tempSUrl <- NULL
tempZUrl <- NULL
tempDep <- NULL
tempVer <- -1
listReady <- FALSE
doList <- function(){
if(is.null(pkgVersion)){
if(tempRep == paste(getOption("repositories"),
"/PACKAGES", sep = "")){
tempSUrl <<- paste(getOption("repositories"), "/",
pkgName, "_", tempVer, ".tar.gz",
sep = "")
tempZUrl <<- avlCheck(pkgName)
}
if(tempVer >= returnList$version){
returnList$repository <<- tempRep
if(!is.null(tempSUrl) && !is.null(tempZUrl))
returnList$packUrl <<- ifelse(type == "unix",
tempSUrl, tempZUrl)
returnList$version <<- tempVer
if(!is.null(tempDep))
returnList$depends <<- formatLine(tempDep)
listReady <<- TRUE
pkgFound <<- FALSE
}
}else{
if(tempVer == returnList$version){
returnList$repository <<- tempRep
if(!is.null(tempSUrl) && !is.null(tempZUrl))
returnList$packUrl <<- ifelse(type == "unix",
tempSUrl, tempZUrl)
returnList$version <<- tempVer
if(!is.null(tempDep))
returnList$depends <<- formatLine(tempDep)
listReady <<- TRUE
pagFound <<- FALSE
}
}
}
for(i in repositories){
pakRep <- getRep(i)
tempRep <- i
for(j in pakRep){
if(isPak(j)){
# doList whenever we see a match
if(pkgFound)
doList()
if(regexpr(pkgPat, j) == 1)
pkgFound <- TRUE
else
pkgFound <- FALSE
}
if(pkgFound){
switch(sub("(^.*): .*", "\\1", j),
"Version" = tempVer <- sub("^.*: *(.*)","\\1",j),
"SourceURL" = tempSUrl <-
sub("^.*(http://.*)","\\1",j),
"Win32URL" = tempZUrl <- sub("^.*(http://.*)","\\1",j),
"Depends" = tempDep <- getDepends(j))
}
}
# do list again in case the match is the last one
if(pkgFound)
doList()
# Taken out to be in line with the new format of PACKAGES
# if(listReady)
# break
}
if(listReady)
return(returnList)
else{
toPut <- ifelse(is.null(pkgVersion), "",
paste(" Version", pkgVersion))
print(paste("Can not find package ", pkgName,
toPut, " in repositories", sep = ""))
return(NULL)
}
}
getDefaultRep <- function (bioCOnly = FALSE){
if(bioCOnly)
return(list(BioC =
"http://www.bioconductor.org/packages/release/distrib/PACKAGES"))
else
return(list(BioC =
"http://www.bioconductor.org/packages/release/distrib/PACKAGES",
CRAN = paste(getOption("repositories"), "/PACKAGES", sep = "")))
}
getRep <- function(rep){
on.exit(options(show.error.messages = TRUE))
con <- url(rep)
options(show.error.messages = FALSE)
tryMe <- try(readLines(con))
#for testing using a local file only
#tryMe <- try(readLines("PACKAGES"))
options(show.error.messages = TRUE)
if(inherits(tryMe, "try-error"))
stop(paste("Invalid repository url", rep))
close(con)
return(tryMe)
}
getPkgPat <- function(pkgName){
return(paste("Package: *", pkgName, sep = ""))
}
isPak <- function(aLine){
return(ifelse(regexpr("Package:.*", aLine) == 1, TRUE, FALSE))
}
getDepends <- function(dep){
on.exit(options(show.error.messages = TRUE))
depList <- NULL
options(show.error.messages = FALSE)
tryMe <- try(sub("^.*: *(.*)","\\1",dep))
options(show.error.messages = TRUE)
if(tryMe == "" || is.null(tryMe) || is.na(tryMe)){
depList <- NULL
}else{
dep <- sub("^.*: *(.*)","\\1",dep)
deps <- unlist(strsplit(dep, ","))
for(i in 1:length(deps)){
depList[[i]] <- deps[i]
}
}
return(depList)
}
formatLine <- function(aLine){
return(gsub("^ *(.*)", "\\1", aLine))
}
avlCheck <- function(pkgName){
on.exit(options(show.error.message = TRUE))
options(show.error.messages = FALSE)
tryMe <- try(url(paste("http://cran.r-project.org/bin/",
"windows/contrib/", pkgName,
".zip", sep = ""), "r"))
if(!inherits(tryMe, "try-error")){
close(tryMe)
return(paste("http://cran.r-project.org/bin/",
"windows/contrib/", pkgName,
".zip", sep = ""))
}
tryMe <- try(url(paste("http://cran.r-project.org/bin/",
"windows/base/", pkgName,
".zip", sep = ""), "r"))
if(!inherits(tryMe, "try-error")){
close(tryMe)
return(paste("http://cran.r-project.org/bin/",
"windows/base/", pkgName,
".zip", sep = ""))
}else{
return("Unavailable")
}
}
|