R/utils.R

Defines functions call_hook aliased ensure_loaded dir_exists is_mac_arm64 is_ubuntu is_linux is_osx is_unix is_windows

"%||%" <- function(x, y) if (is.null(x)) y else x

is_windows <- function() {
  identical(.Platform$OS.type, "windows")
}

is_unix <- function() {
  identical(.Platform$OS.type, "unix")
}

is_osx <- function() {
  Sys.info()["sysname"] == "Darwin"
}

is_linux <- function() {
  identical(tolower(Sys.info()[["sysname"]]), "linux")
}

is_ubuntu <- function() {
  # check /etc/lsb-release
  if (is_unix() && file.exists("/etc/lsb-release")) {
    lsbRelease <- readLines("/etc/lsb-release")
    any(grepl("Ubuntu", lsbRelease))
  } else {
    FALSE
  }
}


is_mac_arm64 <- function() {
  sys_info <- Sys.info()
  sys_info[["sysname"]] == "Darwin" &&
  sys_info[["machine"]] == "arm64"
}

dir_exists <- function(x) {
  utils::file_test('-d', x)
}

ensure_loaded <- function() {
  invisible(tf$`__version__`)
}

aliased <- function(path) {
  sub(Sys.getenv("HOME"), "~", path)
}


call_hook <- function(name, ...) {
  hooks <- getHook(name)
  if (!is.list(hooks))
    hooks <- list(hooks)
  response <- FALSE
  lapply(hooks, function(hook) {
    if (isTRUE(hook(...)))
      response <<- TRUE
  })
  response
}

Try the tensorflow package in your browser

Any scripts or data that you put into this service are public.

tensorflow documentation built on Sept. 28, 2023, 5:06 p.m.