Skip to contents

An Ingredients-class object contains information regarding the name, quantity and units for each ingredient. Although autorecipes provides an Ingredients() constructor, it is unlikely that users will need to call this to create Ingredient-class instances directly. Instead, when creating a RecipeBook-class instance, helper functions are included to read ingredients into the appropriate format such as the RecipeBook() constructor and read_ingredients().

Usage

Ingredients(names, amounts = 1, units = rep(NA_character_, length(names)))

# S4 method for Ingredients
show(object)

# S4 method for Ingredients
names(x)

amounts(x)

units(x)

# S4 method for Ingredients
as.data.frame(x)

Arguments

names

character() containing the names of each ingredient.

amounts

numeric() containing the amounts of each ingredient.

units

character() containing the units for the amount of each ingredient.

object

an Ingredients-class object.

x

an Ingredients-class object.

Slots

names

character() containing the names of each ingredient.

amounts

numeric() containing the amounts of each ingredient.

units

character() containing the units for the amount of each ingredient.

Constructor

Ingredients(names, amounts, units) creates an object of Ingredients-class.

Displaying

show(ingredients) prints each ingredient.

Getters

names(ingredients) obtain the names of each ingredient.

amounts(ingredients) obtain the amounts of each ingredient.

units(ingredients) obtain the units of each ingredient.

as.data.frame(ingredients) converts ingredients to a data.frame.

Examples


Ingredients("salt", 1, "tsp")
#> 1 tsp Salt

# one instance can store multiple ingredients
Ingredients(c("salt", "tomatoes"), c(1, 400), c("tsp", "g"))
#> 1 tsp Salt
#> 400 g Tomatoes

# amounts and units are optional
Ingredients("Chicken")
#> 1 Chicken