A qualified call such as stats::median names the package and the function explicitly. This avoids depending on search-path order.

Program

Play the script to choose a summary function and see the package-qualified call it represents.

namespace_call.R
values <- c(4, 8, 10, 12)
summary_index <- 
summary_name <- c("mean", "median", "sd")[summary_index]
summary_value <- switch(summary_name, mean = base::mean(values), median = stats::median(values), sd = stats::sd(values))
label <- paste(summary_name, round(summary_value, 1), sep = "=")
cat(label, "\n", sep = "")
values <- c(4, 8, 10, 12)
summary_index <- 
summary_name <- c("mean", "median", "sd")[summary_index]
summary_value <- switch(summary_name, mean = base::mean(values), median = stats::median(values), sd = stats::sd(values))
label <- paste(summary_name, round(summary_value, 1), sep = "=")
cat(label, "\n", sep = "")
values <- c(4, 8, 10, 12)
summary_index <- 
summary_name <- c("mean", "median", "sd")[summary_index]
summary_value <- switch(summary_name, mean = base::mean(values), median = stats::median(values), sd = stats::sd(values))
label <- paste(summary_name, round(summary_value, 1), sep = "=")
cat(label, "\n", sep = "")
qualified call `package::function` calls a function from a package namespace explicitly.
switch `switch(summary_name, ...)` selects the expression for the chosen name.
round `round(summary_value, 1)` keeps numeric display stable for replay.