Recall & Review
beginner
What is a function argument in R?
A function argument is a value you give to a function when you call it. It tells the function what data to work with.
Click to reveal answer
beginner
How do you define a function with arguments in R?
You write the function name, then inside parentheses list the argument names. For example:
myfun <- function(x, y) { x + y } defines a function with two arguments, x and y.Click to reveal answer
intermediate
What happens if you call a function without providing all its arguments?
If the function has default values for some arguments, those defaults are used. Otherwise, R will give an error saying an argument is missing.
Click to reveal answer
intermediate
What is a default argument value in R functions?
A default argument value is a value assigned to an argument in the function definition. If you don’t provide that argument when calling the function, R uses the default.
Click to reveal answer
beginner
How can you pass arguments to a function by name in R?
You can specify the argument name when calling the function, like
myfun(y = 5, x = 3). This lets you give arguments in any order.Click to reveal answer
What will happen if you call
sum(1, 2) in R?✗ Incorrect
The sum function adds the numbers 1 and 2 and returns 3.
How do you set a default value for an argument in an R function?
✗ Incorrect
You assign a default value directly in the function definition.
What is the correct way to call a function with named arguments in R?
✗ Incorrect
Named arguments use the syntax
name = value inside the function call.If a function argument has a default value, what happens when you omit it in the call?
✗ Incorrect
R uses the default value if you don’t provide that argument.
Which of these is NOT a valid way to pass arguments to a function in R?
✗ Incorrect
The syntax
x:1 is not valid for passing arguments in R.Explain how function arguments work in R and how default values affect function calls.
Think about what happens when you call a function with fewer arguments than defined.
You got /4 concepts.
Describe how to use named arguments in R function calls and why they might be helpful.
Consider how naming arguments can make your code easier to read and less error-prone.
You got /4 concepts.