check_crucial_names: Check if a named object contains expected names

Description Usage Arguments Value See Also Examples

View source: R/check_crucial_names.R

Description

It is based on: https://www.rdocumentation.org/packages/fgeo.tool/versions/1.2.5/topics/check_crucial_names.

Usage

1
check_crucial_names(x, expected_names)

Arguments

x

A named object.

expected_names

String; expected names of x.

Value

Invisible x, or an error with informative message.

See Also

Other miscellaneous utility functions: degrees(), dropbox_exists(), path_examples(), r2dii_packages()

Examples

 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
x <- c(a = 1)
check_crucial_names(x, "a")
try(check_crucial_names(x, "bad"))

data <- data.frame(a = 1)
check_crucial_names(data, "a")
try(check_crucial_names(data, "bad"))

# Applications for the error class "missing_names" ---------------------

  tryCatch(
    check_crucial_names(x, "bad"),
    error = function(e) class(e)
  )

# Wrapping in try() to allow running examples with no failure
try(
  # What's interesting is this
  tryCatch(
    check_crucial_names(x, "bad"),
    missing_names = function(e) stop(
      "A different error message", call. = FALSE
    )
  )
)

testthat::expect_error(
  check_crucial_names(x, "bad"),
  class = "missing_names"
)

2DegreesInvesting/r2dii.utils documentation built on Jan. 29, 2020, 8:55 a.m.