Functions: Telegram - nopomato/Swirl-lessons GitHub Wiki
The ellipses can be used to pass on arguments to other functions that are
used within the function you're writing. Usually a function that has the
ellipses as an argument has the ellipses as the last argument. The usage of
such a function would look like:
ellipses_func(arg1, arg2 = TRUE, ...)
In the above example arg1 has no default value, so a value must be provided
for arg1. arg2 has a default value, and other arguments can come after arg2
depending on how they're defined in the ellipses_func() documentation.
Interestingly the usage for the paste function is as follows:
paste (..., sep = " ", collapse = NULL)
Notice that the ellipses is the first argument, and all other arguments after
the ellipses have default values. This is a strict rule in R programming: all
arguments after an ellipses must have default values. Take a look at the
simon_says function below:
simon_says <- function(...){
paste("Simon says:", ...)
}
The simon_says function works just like the paste function, except the
begining of every string is prepended by the string "Simon says:"
Telegrams used to be peppered with the words START and STOP in order to
demarcate the beginning and end of sentences. Write a function below called
telegram that formats sentences for telegrams.
telegram("Good", "morning")
should evaluate to:
For example the expression "START Good morning STOP"
telegram <- function(...){ paste("START",...,"STOP") }