A consultant intends to charge 55 Canadian dollars per hour for four hours. The saved script is:
service_hours <- 4 hourly_fee <- 55 estimate <- service_hours * hourly_rate print(estimate)
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?
Enter hourly_rate <- 55 manually in each user's console before running the unchanged script.
Move hourly_fee <- 55 before service_hours <- 4, leaving the calculation unchanged.
Replace hourly_rate with hourly_fee in the calculation, leaving the other commands unchanged.
Move print(estimate) before the calculation, leaving the remaining commands unchanged.
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.
Apply named arguments and default values
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.
Calculate the dollar amount returned by each call below. Enter both amounts to two decimal places.
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.