R/conditions.R

Defines functions package_required package_required_error is_torch_tensor not_implemented_error runtime_error value_warning value_error type_error

type_error <- function(msg) {
  rlang::abort(msg, class = "type_error")
}

value_error <- function(msg) {
  rlang::abort(msg, class = "value_error")
}

value_warning <- function(msg) {
  rlang::warn(msg, class = "value_warning")
}

runtime_error <- function(msg) {
  rlang::abort(msg, class = "runtime_error")
}

not_implemented_error <- function(msg) {
  rlang::abort(msg, class = "not_implemented_error")
}

is_torch_tensor <- function(x) {
  inherits(x, "torch_tensor")
}

package_required_error <- function(pkg) {
  runtime_error(glue::glue("Package {pkg} required but not found. Please run install.packages('{pkg}') to install it."))
}

package_required <- function(pkg) {
  if(!requireNamespace(pkg, quietly = TRUE))
    package_required_error(pkg)
}

Try the torchaudio package in your browser

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

torchaudio documentation built on Feb. 16, 2023, 9:41 p.m.