File: inet.R

package info (click to toggle)
r-cran-biocmanager 1.30.20%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 348 kB
  • sloc: sh: 13; makefile: 2
file content (132 lines) | stat: -rw-r--r-- 3,209 bytes parent folder | download | duplicates (2)
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
#' @importFrom utils available.packages install.packages old.packages
#'     update.packages
NULL

.inet_warning <-
    function(w)
{
    if (.is_CRAN_check()) {
        .message(conditionMessage(w))
    } else {
        warning(w)
    }
    invokeRestart("muffleWarning")
}

.inet_error <-
    function(e)
{
    if (.is_CRAN_check()) {
        .message(conditionMessage(e))
    } else {
        stop(e)
    }
}

.inet_readChar <-
    function(...)
{
    withCallingHandlers({
        tryCatch({
            readChar(...)
        }, error = function(e) {
            .inet_error(e)
            character()
        })
    }, warning = .inet_warning)
}

.inet_readLines <-
    function(...)
{
    withCallingHandlers({
        tryCatch({
            readLines(...)
        }, error = function(e) {
            .inet_error(e)
            e
        })
    }, warning = .inet_warning)
}

.inet_available.packages <-
    function(...)
{
    withCallingHandlers({
        tryCatch({
            available.packages(...)
        }, error = function(e) {
            .inet_error(e)
            colnames <- c(
                "Package", "Version", "Priority", "Depends",
                "Imports", "LinkingTo", "Suggests", "Enhances",
                "License", "License_is_FOSS", "License_restricts_use",
                "OS_type", "Archs", "MD5sum", "NeedsCompilation",
                "File", "Repository"
            )
            matrix(character(0), ncol = 17, dimnames = list(NULL, colnames))
        })
    }, warning = .inet_warning)
}        

.inet_install.packages <-
    function(...)
{
    ## More generous timeout for large package download, see
    ## `?download.file` and, for instance,
    ## https://stat.ethz.ch/pipermail/bioc-devel/2020-November/017448.html
    if (identical(as.integer(getOption("timeout")), 60L)) { # change default only
        otimeout <- options(timeout = 300L)
        on.exit(options(otimeout))
    }
    withCallingHandlers({
        tryCatch({
            install.packages(...)
        }, error = function(e) {
            .inet_error(e)
            invisible(NULL)
        })
    }, warning = function(w) {
        msg <- conditionMessage(w)
        if (grepl("not available", msg)) {
            msg <- gsub(
                "this version of R",
                paste0("Bioconductor version ", "'", version(), "'"),
                msg
            )
            w <- simpleWarning(msg, conditionCall(w))
        }
        .inet_warning(w)
    })
}

.inet_old.packages <-
    function(...)
{
    withCallingHandlers({
        tryCatch({
            old.packages(...)
        }, error = function(e) {
            .inet_error(e)
            invisible(NULL)
        })
    }, warning = .inet_warning)
}        

.inet_update.packages <-
    function(...)
{
    ## see .inet_old.packages for implementation note
    if (identical(as.integer(getOption("timeout")), 60L)) {
        otimeout <- options(timeout = 300L)
        on.exit(options(otimeout))
    }
    withCallingHandlers({
        tryCatch({
            update.packages(...)
        }, error = function(e) {
            .inet_error(e)
            invisible(NULL)
        })
    }, warning = .inet_warning)
}