Learn R Programming

Dict (version 0.6)

entries: Converts a dictionary to a list of key/value pairs

Description

Converts a dictionary into a list of entries containing key/value pairs, of the form list(entry(key = key1, value = value1), entry(key = key2, value = value2), ...). Each element of the list is a list containing a key element and a value element, created using the entry function. A list of entries can be collected back into a dictionary using the collect function.

Usage

entries(dict)

Arguments

dict
a dictionary

Value

a list containing lists with two items, key and value, for each entry in the dictionary.

Examples

Run this code
solar_system <- dict(Mercury = 0.387, Venus = 0.723, Earth = 1, Mars = 1.524)
for (e in entries(solar_system))
   cat('The distance between planet', e$key, ' and the Sun is', e$value, ' AU.\n')

inner_solar_system <- entries(solar_system) %>%
             keep(function(e) e$value <= 1) %>%
             collect()

Run the code above in your browser using DataLab