Skip to content

Instantly share code, notes, and snippets.

@arraytools
Last active December 10, 2015 19:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save arraytools/4484270 to your computer and use it in GitHub Desktop.
Understand how *source("http://www.bioconductor.org/biocLite.R")* works. 1. After source("http://www.bioconductor.org/biocLite.R"), it checks R version and bioc version. 2. If it satisfies the condition (vers > "2.13" && biocVers > "2.8"), it will try to load *BiocInstaller* package. If loading BiocInstaller package is successful, then *biocLite…
## Mirrors: uncomment the following and change to your favorite CRAN mirror
## if you don't want to use the default (cran.fhcrc.org, Seattle, USA).
## options("repos" = "http://cran.fhcrc.org")
## Mirrors: uncomment the following and change to your favorite Bioconductor
## mirror, if you don't want to use the default (www.bioconductor.org,
## Seattle, USA)
## options("BioC_mirror" = "http://www.bioconductor.org")
local({
vers <- getRversion()
biocVers <-
tryCatch(tools:::.BioC_version_associated_with_R_version,
error=function(...) numeric_version(0.0))
if (vers > "2.13" && biocVers > "2.8") {
if ("biocLite" %in% ls(envir=.GlobalEnv)) {
message <- paste("You have an outdated biocLite() function.",
"Run 'rm(biocLite)' and try again.")
stop(message)
}
if (!suppressWarnings(require("BiocInstaller", quietly=TRUE))) {
a <- NULL
p <- file.path(Sys.getenv("HOME"), ".R", "repositories")
if (file.exists(p)) {
a <- tools:::.read_repositories(p)
if (!"BioCsoft" %in% rownames(a))
a <- NULL
}
if (is.null(a)) {
p <- file.path(R.home("etc"), "repositories")
a <- tools:::.read_repositories(p)
}
if (!"package:utils" %in% search()) {
url <- "http://bioconductor.org/biocLite.R"
txt <- sprintf("use 'source(\"%s\")' to update 'BiocInstaller'
after 'utils' package is attached",
url)
message(paste(strwrap(txt), collapse="\n "))
} else {
## add a conditional for each R (or another solution)
if (vers >= "2.15" && vers < "2.16") {
a["BioCsoft", "URL"] <- sub(as.character(biocVers), "2.11",
a["BioCsoft", "URL"])
biocVers <- numeric_version("2.11")
} else if (vers == "2.16" || vers == "3.0") {
a["BioCsoft", "URL"] <- sub(as.character(biocVers), "2.12",
a["BioCsoft", "URL"])
biocVers <- numeric_version("2.12")
}
install.packages("BiocInstaller", repos=a["BioCsoft", "URL"])
if (!suppressWarnings(require("BiocInstaller",
quietly=TRUE))) {
url0 <- "http://www.bioconductor.org/packages"
url <- sprintf("%s/%s/bioc",
url0, as.character(biocVers))
txt0 <- "'biocLite.R' failed to install 'BiocInstaller',
use 'install.packages(\"%s\", repos=\"%s\")'"
txt <- sprintf(txt0, "BiocInstaller", url)
message(paste(strwrap(txt), collapse="\n "))
}
}
}
} else {
source("http://bioconductor.org/getBioC.R")
biocLite <<-
function(pkgs, groupName="lite", ...)
{
if (missing(pkgs))
biocinstall(groupName=groupName, ...)
else
biocinstall(pkgs=pkgs, groupName=groupName, ...)
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment