uris <- c("cc:license", "dc:title")
ns <- c(dc = "http://purl.org/dc/elements/1.1/",
dcterms = "http://purl.org/dc/terms/",
dct = "http://purl.org/dc/terms/",
cc = "http://creativecommons.org/ns#")
# expansion is vectorized
expand_prefix(uris, ns)
# strings with non-matching or no prefix are left as is
uris <- c(uris, "my:title", "title")
expand_prefix(uris, ns)
# NAs in the input list become NA in the output
uris <- c(uris, NA)
expand_prefix(uris, ns)
# can include a "base" (unnamed) namespace for expanding unprefixed strings
ns <- c(ns, "//local/")
xuris <- expand_prefix(uris, ns)
xuris
xuris[uris == "title"] == paste0("//local/", uris[uris == "title"])
# different prefixes may expand to the same result
expand_prefix("dcterms:modified", ns) == expand_prefix("dct:modified", ns)
# or they may result in different expansions
expand_prefix("dc:title", ns) != expand_prefix("dcterms:title", ns)
Run the code above in your browser using DataLab