Let's order pizza!
As a final exercise in using paste() and to celebrate getting to the end of the first chapter, let's order some pizza.
We've got a list of possible pizza toppings in toppings.
You are going to randomly select three toppings, and then put them together using paste() into an order for pizza, that should result in a string like,
"I want to order a pizza with mushrooms, spinach, and pineapple."
Este exercício faz parte do curso
String Manipulation with stringr in R
Instruções do exercício
- Print
my_toppingsto see your random toppings. - Add
"and "to the start of the third element by usingpaste()withmy_toppingsand a vector you define. - Create a vector
these_toppingsby usingpaste()to collapsemy_toppings_andwith a comma and space between each element. - Create
my_orderby pasting"I want to order a pizza with "tothese_toppingsand ending with a period,".". - Order your pizza by calling
writeLines()onmy_order. - Try re-running all your code (including the sampling of toppings). You should get a brand new pizza order!
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Randomly sample 3 toppings
my_toppings <- sample(toppings, size = 3)
# Print my_toppings
___
# Paste "and " to last element: my_toppings_and
my_toppings_and <- ___
# Collapse with comma space: these_toppings
these_toppings <- ___
# Add rest of sentence: my_order
my_order <- ___
# Order pizza with writeLines()
___