What is verbose in R?

Ever heard of the words verbose and non-verbose in the English language?

In straightforward language, we characterize the two words as:

  1. Verbose: A text containing a lot of words.

    1. Could be more words than necessary.

    2. Resembles the expression "full of".

  2. Non-verbose: A text not composed of many words.

    1. To the point.

    2. Clear and concise, may eliminate minor details.

Just like these English words, the verbose argument in an R function targets the wordiness of an output.

Note: R is a programming language mainly used in the domains of statistics and data analysis.

English analogy

The verbose argument in R

In R, the verbose argument is a common parameter that is used in functions to control the level of output or messages displayed during the execution of the function. It allows us to toggle between verbose i.e. a detailed output and non-verbose i.e. a concise output based on your specific needs.

It's a pretty great tool that just requires a true or a false from our side and can alter our output for us accordingly in just a matter of seconds!

How to use verbose as an argument
How to use verbose as an argument
Question

Why is verbose an argument?

Show Answer

Possible values for verbose

The verbose argument is a logical parameter, represented by Boolean variables. This argument accepts either TRUE or FALSE values.

  • TRUE: When we wish to keep the details of our output as they are.

  • FALSE: When we wish to keep our output minimal.

Let's now map our English definitions to the argument we've just learned.

R and English mapping

Code examples

This argument has many real-world applications and is highly useful for us as developers. Let's explore a few possibilities and see how it works.

verbose = FALSE

calculateSum <- function(numbers, verbose = FALSE) {
if (verbose) {
cat("We are now going to perform calculations \n")
}
resultSum <- sum(numbers)
if (verbose) {
cat("The calculated sum is:", resultSum, "\n")
}
return(resultSum)
}
# our input
inputNumbers <- c(2, 4, 6, 8, 10)
# calculating the sum without verbose output
calculateSum(inputNumbers, verbose = FALSE)

Note: See how only the sum is shown and the code recognizes what to print.

verbose = TRUE

calculateSum <- function(numbers, verbose = TRUE) {
if (verbose) {
cat("We are now going to perform calculations \n")
}
resultSum <- sum(numbers)
if (verbose) {
cat("The calculated sum is:", resultSum, "\n")
}
return(resultSum)
}
# our input
inputNumbers <- c(2, 4, 6, 8, 10)
# calculating the sum with verbose output
calculateSum(inputNumbers, verbose = TRUE)

Code explanation

This explanation covers both situations and what the output might be in both cases.

  • Line 1: We define a function calculateSum in R that takes in a vector of digits named as numbers, as well as the verbose parameter, which is either set to TRUE or FALSE.

  • Lines 2–4: If the verbose argument is true we print "We are now going to perform calculations". Otherwise, this line is skipped to keep the output concise.

  • Line 6: The built-in sum method is called on the elements of numbers and is saved in a variable named resultSum.

  • Lines 8–10: If the verbose argument is TRUE we print "The calculated sum is: ", followed by the resultSum. Otherwise, just the resultSum is shown.

  • Line 12: The method returns the calculated sum using resultSum.

  • Line 16: We define inputNumbers as the input vector we'll be passing to our function.

  • Line 19: Finally, we call our calculateSum method and it renders the output.

Output

Check out the difference between the rendered outputs, just by adding a single verbose argument.

The verbose argument is TRUE here
The verbose argument is TRUE here
The verbose argument is FALSE here
The verbose argument is FALSE here
Detailed and concise output users both can make use of the verbose argument
Detailed and concise output users both can make use of the verbose argument

Use cases of verbose = TRUE

  • Debugging: When troubleshooting or debugging code, setting the verbose argument to true helps us understand the execution flow, variable values, and intermediate results. This directly aids in quickly identifying issues.

  • Progress tracking: For long-running tasks, enabling verbose output allows us to track progress by displaying informative messages or even progress indicators at different stages.

Use cases of verbose = FALSE

  • Production environment: In a production environment, we usually wish to minimize unnecessary output. So, setting the verbose argument to False in this case, helps in reducing clutter and improving efficiency.

  • User interface (UI): When integrating code with a user interface or interactive application, non-verbose output helps us ensure a clean and concise display for the end-users. Therefore, we can achieve the goal to avoid overwhelming them with excessive information.

It’s quiz time!

Question

Why is verbose useful in debugging?

Show Answer

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved