Functions to check if an object is a keyvalue object, or coerce it if possible.

as.keyvalue(x, ...)

# S3 method for data.frame
as.keyvalue(x, standard_var_names = NULL, ...)

# S3 method for default
as.keyvalue(x, y, ...)

is.keyvalue(x)

Arguments

x

object to test for, or coerce to, keyvalue (see the details).

...

arguments passed between methods

standard_var_names

a character vector with standard names for variables decoded with this key-values.

y

a value vector if x is an unnamed vector (argument must be named 'y = .')

Value

as.keyvalue returns a data.frame with additional class keyvalue that fulfills the requirements for a keyvalue object and with the key column as character. It also has two extra attributes standard_var_names as described above and keyvalue11 which is TRUE for keyvalue objects with a 1:1 relation between its keys and values (otherwise FALSE).

Details

x can be of:

  • a name of a package internal (or external) keyvalue object (character of length one)

  • a data.frame with two columns "key" (with unique cells) and "value".

  • a list as described in as.keyvalue.list

  • a named vector with all names unique

  • an unnamed vector with unique cells if supplemented by additional vector (y)

See also

Examples

snomed2 <- as.keyvalue(snomed) is.keyvalue(snomed2)
#> [1] TRUE
summary(snomed2)
#> $data.frame.summary #> key value #> Length:831 Length:831 #> Class1:key Class1:value #> Class2:value Class2:character #> Class3:character Mode :character #> Mode :character #> #> $standard_var_names #> NULL #> #> $nonunique #> key value #> 393 90703 Embryonalt carcinom #> 402 90723 Embryonalt carcinom #> 592 96153 Hårcellsleukemi #> 787 99403 Hårcellsleukemi #> 354 89643 Klarcellssarkom #> 381 90443 Klarcellssarkom #> 587 96073 Mantelcellslymfom #> 646 96733 Mantelcellslymfom #> 710 97423 Mastcellsleukemi #> 769 99003 Mastcellsleukemi #> 209 85103 Medullär cancer #> 215 85113 Medullär cancer #> 392 90701 Misstänkt embryonalt carcinom #> 396 90721 Misstänkt embryonalt carcinom #> 353 89641 Misstänkt klarcellssarkom #> 378 90441 Misstänkt klarcellssarkom #> 707 97333 Plasmacellsleukemi #> 741 98303 Plasmacellsleukemi #> 162 84001 Svettkörtelcancer in situ #> 163 84002 Svettkörtelcancer in situ #> 168 84101 Talgkörtelcancer in situ #> 171 84102 Talgkörtelcancer in situ #> 73 813021 Urotelialt carcinom, papillärt, icke invasivt #> 74 813022 Urotelialt carcinom, papillärt, icke invasivt #> 75 813031 Urotelialt carcinom, papillärt, invasivt #> 76 813032 Urotelialt carcinom, papillärt, invasivt #> 77 813033 Urotelialt carcinom, papillärt, invasivt #> 79 812031 Urotelialt carcinom, UNS, inklusive cytologi #> 80 812032 Urotelialt carcinom, UNS, inklusive cytologi #> 81 812033 Urotelialt carcinom, UNS, inklusive cytologi #>