File: has.R

package info (click to toggle)
r-cran-igraph 2.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 27,772 kB
  • sloc: ansic: 206,420; cpp: 21,827; fortran: 4,090; yacc: 1,229; lex: 518; sh: 52; makefile: 8
file content (35 lines) | stat: -rw-r--r-- 722 bytes parent folder | download
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
make_closure <- function(fun, ...) {
  data <- list(...)
  mapply(assign, names(data), data, MoreArgs = list(pos = environment()))
  environment(fun) <- environment()
  fun
}

has_glpk <- make_closure(glpk = NULL, function() {
  if (is.null(glpk)) {
    glpk <<- tryCatch(
      {
        cluster_optimal(make_ring(10))
        TRUE
      },
      error = function(e) FALSE
    )
  }
  glpk
})

has_graphml <- make_closure(graphml = NULL, function() {
  if (is.null(graphml)) {
    graphml <<- tryCatch(
      {
        read_graph(
          rawConnection(charToRaw("<graphml><graph></graph></graphml>")),
          format = "graphml"
        )
        TRUE
      },
      error = function(e) FALSE
    )
  }
  graphml
})