A service business uses the following R function to calculate a charge in dollars. The hourly rate is in dollars per hour, and the booking fee is in dollars. No taxes or other charges apply.
service_charge <- function(hours, rate = 24, booking_fee = 9) { hours * rate + booking_fee }
Calculate the dollar amount returned by each call below. Enter both amounts to two decimal places.
service_charge(booking_fee = 7, hours = 3) service_charge(rate = 29, hours = 3)
Unlock full course notes by signing up
Trace a stored subtotal
An office manager runs all these R commands in the order shown. The unit price is in Canadian dollars, and items is the number ordered.
What happens at the final command?
Check arithmetic before building a price
Before building a pricing calculation, an analyst checks how R evaluates the following arithmetic expressions. Complete the table with the exact integer stored in each object.
Repair a hidden session dependency
A consultant intends to charge 55 Canadian dollars per hour for four hours. The saved script is:
In the author's session, hourly_rate already contains 70 from earlier work, so the script displays 280. In a colleague's fresh session, it stops with an object-not-found error for hourly_rate.
Which change makes the saved script self-contained and calculates the intended estimate?
Rebuild and update an equipment quote
An equipment-hire quote consists of a booking fee of 36 Canadian dollars plus 24 Canadian dollars per day. Tax is excluded. A colleague saves these commands in equipment_quote.R:
Assume the script is first run in a fresh R session.
Explain why its first command fails.