calculatePrice: calculate price

Description Usage Arguments Details Value Examples

Description

calculatePrice() calculates the best price of the existing shopping cart. That means at first every meaningful combination of any discount offers is calculated. Than the cheapest way is filtered and returned. This functions acts as a convenient wrapper for the functions analyseShoppingCart(), enumerateCombinations(), extractDiscountSets() and calculateBestDiscount().

Usage

1
2
calculatePrice(shoppingCart, discountInfos, pricePerItem,
  intermediateSteps = FALSE)

Arguments

shoppingCart

shopping cart as an data.frame with one row for one item

discountInfos

tibble or data.frame which contains information about the sets and their discount; read details

pricePerItem

numerical price for one item; Currently only one price is allowed

intermediateSteps

if it's set to TRUE, intermediate steps are shown; default is FALSE

Details

Currently the argument discountInfos needs one special format: It needs two columns: 1. The first one is called set and contains numerical information about the discount sets' possibilities (read examples) 2. The second one is called discount and contains numerical information about the discount. Further the argument shoppingCart requires some specific formatting, since no generalisation has been implemented yet (analyseShoppingCart already has this generalisation). These requirements are: 1. shoppingCart need to be a data.frame with... 2. ...two columns. The first need to be called itemID and contains the ID of every item. The second one is named name and contains the name of the item.

Value

Depending on intermediateSteps, only a numerical vector is returned or a list which additionally contains the intermediate steps.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
```
# These books are available in the shop
books <- dplyr::tibble(
  itemID = 1:5,
  name = c(
    "Stein der Weisen",
    "Kammer des Schreckens",
    "Gefangene von Askaban",
    "Feuerkelch",
    "Orden des Phönix"
  )
)

set.seed(1)
shoppingCart <- dplyr::sample_n(books, 15, replace = TRUE) %>%
  dplyr::arrange(itemID)

discountTibble <- dplyr::tibble(
  set = 1:5,
  discount = c(0, 5, 10, 20, 25)
)

calculatePrice(shoppingCart, discountTibble, pricePerItem = 8)
```

frumentum/BuyPotterSaveMoney documentation built on May 15, 2019, 10:49 a.m.