Reproducible code:
Meal <- function(name, ingredients, time_to_cook = NA, time_of_day = "Dinner", cuisine = NA) {
m <- list(name = name, ingredients = ingredients, time = time_to_cook, meal = time_of_day, cuisine = cuisine)
m
}
burritos <- Meal("Burrito", ingredients = c("Tortilla", "Chicken Breast", "Sour Cream", "Pepper", "Onion", "Chili Paste"), time_to_cook = "Fast", cuisine = "Mexican")
pizza <- Meal("Pizza", ingredients = c("Flour", "Tinned Tomato", "Mozarella", "Garlic"))
rbind(data.frame(pizza), data.frame(burritos))
name ingredients time meal cuisine
1 Pizza Flour <NA> Dinner <NA>
2 Pizza Tinned Tomato <NA> Dinner <NA>
3 Pizza Mozarella <NA> Dinner <NA>
4 Pizza Garlic <NA> Dinner <NA>
5 Burrito Tortilla Fast Dinner Mexican
6 Burrito Chicken Breast Fast Dinner Mexican
7 Burrito Sour Cream Fast Dinner Mexican
8 Burrito Pepper Fast Dinner Mexican
9 Burrito Onion Fast Dinner Mexican
10 Burrito Chili Paste Fast Dinner Mexican
The behavior I would prefer is if ingredients was not converted into long format, ie keep Ingredients as a list, rather than one row for each ingredient. Is there any way I can get that behavior?
I don't want to go all the way and use relational databases, was wondering if there is a simple way to handle this.