summaryrefslogtreecommitdiffstats
path: root/src/arrow/ci/etc/rprofile
blob: 5ef1dca8ff38197245efbf386f56288dbdc4d31b (plain)
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
 local({
  .pick_cran <- function() {
    # Return a CRAN repo URL, preferring RSPM binaries if available for this OS
    rspm_template <- "https://packagemanager.rstudio.com/cran/__linux__/%s/latest"
    supported_os <- c("focal", "xenial", "bionic", "centos7", "centos8", "opensuse42", "opensuse15", "opensuse152")

    if (nzchar(Sys.which("lsb_release"))) {
      os <- tolower(system("lsb_release -cs", intern = TRUE))
      if (os %in% supported_os) {
        return(sprintf(rspm_template, os))
      }
    }
    if (file.exists("/etc/os-release")) {
      os_release <- readLines("/etc/os-release")
      vals <- sub("^.*=(.*)$", "\\1", os_release)
      os <- intersect(vals, supported_os)
      if (length(os)) {
        # e.g. "bionic"
        return(sprintf(rspm_template, os))
      } else {
        names(vals) <- sub("^(.*)=.*$", "\\1", os_release)
        if (vals["ID"] == "opensuse") {
          version <- sub('^"?([0-9]+).*"?.*$', "\\1", vals["VERSION_ID"])
          os <- paste0("opensuse", version)
          if (os %in% supported_os) {
            return(sprintf(rspm_template, os))
          }
        }
      }
    }
    if (file.exists("/etc/system-release")) {
      # Something like "CentOS Linux release 7.7.1908 (Core)"
      system_release <- tolower(utils::head(readLines("/etc/system-release"), 1))
      # Extract from that the distro and the major version number
      os <- sub("^([a-z]+) .* ([0-9]+).*$", "\\1\\2", system_release)
      if (os %in% supported_os) {
        return(sprintf(rspm_template, os))
      }
    }

    return("https://cloud.r-project.org")
  }

  options(
    Ncpus = parallel::detectCores(),
    repos = tryCatch(.pick_cran(), error = function(e) "https://cloud.r-project.org"),
    HTTPUserAgent = sprintf(
      'R/%s R (%s)',
      getRversion(),
      paste(getRversion(), R.version$platform, R.version$arch, R.version$os)
    )
  )

  # there's a bug in 3.5 that will warn/error on these, so only set it around that
  if (getRversion() >= "3.6.0" || getRversion() < "3.5.0") {
    options(
      warnPartialMatchAttr = TRUE,
      warnPartialMatchDollar = TRUE,
      warnPartialMatchArgs = TRUE
    )
  }
})