I'm trying to complete the Functions lesson for Rprogramming and although my mad_libs function code was accepted as "correct" by swirl and I'm able to move on, the print out only ever has blanks for the arguments. Below is my code and print out
mad_libs <- function(...){
# Do your argument unpacking here!
args <- list(...)
place <- args[["place"]]
adjective <- args[["adjective"]]
noun <- args[["noun"]]
# Don't modify any code below this comment.
# Notice the variables you'll need to create in order for the code below to
# be functional!
paste("News from", place, "today where", adjective, "students took to the streets in protest of the new", noun, "being installed on campus.")
}
mad_libs("DC", "energetic", "statue")
[1] "News from today where students took to the streets in protest of the new being installed on campus."
You're so close! Don't forget that you have to pass named arguments into the function in order to capture those arguments from args
.
Hello!
I had the same issue, and then succeeded when using:
mad_libs(place = 'Paris', adjective = 'sparkly', noun = 'fork')
However, I'm having trouble understanding why we are using a '...' here, since there are only 3 arguments/variables anyway. Any clarity would really be appreciated!
Thank you!
Hi @TStas,
The purpose of this question is to demonstrate how ...
works, that's all.
Oh, thank you!
Most helpful comment
Hello!
I had the same issue, and then succeeded when using:
mad_libs(place = 'Paris', adjective = 'sparkly', noun = 'fork')
However, I'm having trouble understanding why we are using a '...' here, since there are only 3 arguments/variables anyway. Any clarity would really be appreciated!
Thank you!