Test for Valid URIs
is_uri.RdThis is a vectorized predicate to test if character values are valid URLs, i.e. have a scheme and at least one of: hostname or path (according to RFC3986).
Arguments
- x
A character vector.
- empty_ok
Whether to allow empty hosts and paths, as a boolean (default:
TRUE). RFC3986 allows for empty paths & hosts, potentially making a scheme alone valid and, therefore, the default. However, it is often desirable to validate that at least one of these is NOT empty, since a scheme alone is rarely useful in practice.
Notes
While all URIs are valid CURIEs (see is_curie(def = "w3c")), not all CURIEs
are valid URIs (e.g. URIs cannot start with _).
See also
Other ID predicates:
is_curie(),
obo_ID_predicates
Other predicates:
all_duplicated(),
char_val_predicates,
iff_all_vals(),
is_curie(),
is_invariant(),
lgl_predicates,
num_val_predicates,
obo_ID_predicates
Examples
.uri <- c(
# always TRUE
"http://purl.obolibrary.org/obo/DOID_0001816",
"https://google.com",
"mailto:fake.name@blah.com",
# TRUE, if empty_ok = FALSE
"file://",
"mailto:",
# never TRUE
"blah",
""
)
is_uri(.uri)
#> [1] TRUE TRUE TRUE TRUE TRUE FALSE FALSE
is_uri(.uri, empty_ok = FALSE)
#> [1] TRUE TRUE TRUE FALSE FALSE FALSE FALSE