modified: pixi.toml
[GalaxyCodeBases.git] / R / mirrored / biocLite.R
blob6d52d1e728a33ea905507658ead6c4704b59509a
1 ## Mirrors: uncomment the following and change to your favorite CRAN mirror
2 ## if you don't want to use the default (cran.fhcrc.org, Seattle, USA).
3 ## options("repos" = c(CRAN="http://cran.fhcrc.org"))
5 ## Mirrors: uncomment the following and change to your favorite Bioconductor
6 ## mirror, if you don't want to use the default (www.bioconductor.org,
7 ## Seattle, USA)
8 ## options("BioC_mirror" = "http://www.bioconductor.org")
10 local({
12     vers <- getRversion()
13     biocVers <- tryCatch({
14         BiocInstaller::biocVersion() # recent BiocInstaller
15     }, error=function(...) {         # no / older BiocInstaller
16         BioC_version_associated_with_R_version <-
17             get(".BioC_version_associated_with_R_version",
18                 envir=asNamespace("tools"), inherits=FALSE)
19         if (is.function(BioC_version_associated_with_R_version))
20             BioC_version_associated_with_R_version()
21         else                            # numeric_version
22             BioC_version_associated_with_R_version
23     })
25     if (vers < "3.0") {
26         ## legacy; no need to change "3.0" ever
27         ## coordinate this message with .onAttach
28         txt <- strwrap("A new version of Bioconductor is available
29             after installing the most recent version of R; see
30             http://bioconductor.org/install", exdent=2)
31         message(paste(txt, collapse="\n"))
32     } else if ("package:BiocInstaller" %in% search()) {
33         ## messages even if already attached
34         tryCatch(BiocInstaller:::.onAttach(), error=function(...) NULL)
35     }
37     if (vers > "2.13" && biocVers > "2.8") {
39         if (exists("biocLite", .GlobalEnv, inherits=FALSE)) {
40             txt <- strwrap("There is an outdated biocLite() function in the
41                 global environment; run 'rm(biocLite)' and try again.")
42             stop("\n", paste(txt, collapse="\n"))
43         }
45         if (!suppressWarnings(require("BiocInstaller", quietly=TRUE))) {
46             a <- NULL
47             p <- file.path(Sys.getenv("HOME"), ".R", "repositories")
48             if (file.exists(p)) {
49                 a <- tools:::.read_repositories(p)
50                 if (!"BioCsoft" %in% rownames(a)) 
51                     a <- NULL
52             }
53             if (is.null(a)) {
54                 p <- file.path(R.home("etc"), "repositories")
55                 a <- tools:::.read_repositories(p)
56             }
57             if (!"package:utils" %in% search()) {
58                 url <- "http://bioconductor.org/biocLite.R"
59                 txt <- sprintf("use 'source(\"%s\")' to update 'BiocInstaller'
60                                 after 'utils' package is attached",
61                                url)
62                 message(paste(strwrap(txt), collapse="\n  "))
63             } else {
64                 ## add a conditional for Bioc releases occuring WITHIN
65                 ## a single R minor version. This is so that a user with a
66                 ## version of R (whose etc/repositories file references the
67                 ## no-longer-latest URL) and without BiocInstaller
68                 ## will be pointed to the most recent repository suitable
69                 ## for their version of R
70                 if (vers == "3.2.0") {
71                     a["BioCsoft", "URL"] <- sub(as.character(biocVers), "3.1",
72                       a["BioCsoft", "URL"])
73                 } else if (vers == "3.1.1") {
74                     ## R-3.1.1's etc/repositories file at the time of the release 
75                     ## of Bioc 3.0 pointed to the 2.14 repository, but we want 
76                     ## new installations to access the 3.0 repository
77                     a["BioCsoft", "URL"] <- sub(as.character(biocVers), "3.0",
78                       a["BioCsoft", "URL"])
79                 } else if (vers == "3.1.0") {
80                     ## R-devel points to 2.14 repository
81                     a["BioCsoft", "URL"] <- sub(as.character(biocVers), "2.14",
82                       a["BioCsoft", "URL"])
83                 } else if (vers >= "2.15" && vers < "2.16") {
84                     a["BioCsoft", "URL"] <- sub(as.character(biocVers), "2.11",
85                       a["BioCsoft", "URL"])
86                     biocVers <- numeric_version("2.11")
87                 }
88                 install.packages("BiocInstaller", repos=a["BioCsoft", "URL"])
89                 if (!suppressWarnings(require("BiocInstaller",
90                                               quietly=TRUE))) {
91                     url0 <- "http://www.bioconductor.org/packages"
92                     url <- sprintf("%s/%s/bioc",
93                                    url0, as.character(biocVers))
94                     txt0 <- "'biocLite.R' failed to install 'BiocInstaller',
95                             use 'install.packages(\"%s\", repos=\"%s\")'"
96                     txt <- sprintf(txt0, "BiocInstaller", url)
97                     message(paste(strwrap(txt), collapse="\n  "))
98                 }
99             }
100         } else {
101              ## BiocInstaller version 1.16.0-1.18.1 do not
102              ## automatically update when type=="source"; notify users
103              ## when they have updated R over their old libraries
104              installerVersion <- utils::packageVersion("BiocInstaller")
105              test0 <- (vers > "3.1.2") &&
106                  !identical(getOption("pkgType"), "source") &&
107                      (installerVersion >= "1.16.0") &&
108                          (installerVersion <= "1.16.4")
109              if (test0) {
110                  if (installerVersion < "1.16.4") {
111                      txt <- "Update BiocInstaller with
112                          oldPkgType=options(pkgType=\"source\");
113                          biocLite(\"BiocInstaller\"); options(oldPkgType)"
114                      message(paste(strwrap(txt, exdent=2), collapse="\n"))
115                  }
116                  if (vers >= "3.2") {
117                      txt <- sprintf("BiocInstaller version %s is too old for
118                      R version %s; remove.packages(\"BiocInstaller\"),
119                      re-start R, then
120                      source(\"http://bioconductor.org/biocLite.R\")",
121                                     biocVers, vers)
122                      warning(paste(strwrap(txt, exdent=2), collapse="\n"))
123                  }
124              }
125          }
126     } else {
127         source("http://bioconductor.org/getBioC.R")
128         biocLite <<-
129             function(pkgs, groupName="lite", ...)
130             {
131                 if (missing(pkgs))
132                     biocinstall(groupName=groupName, ...)
133                 else
134                     biocinstall(pkgs=pkgs, groupName=groupName, ...)
135             }
136     }