Stack Exchange
How does sapply() apply a function with undefined (with no default) parameters
The following code block taken from chernan's sample REST queries will apply FUN to a list of parameters, but "param_name" is not provided.  How is this possible?
rcurl_request <- function(service_url, parameters) {

# Collapse all parameters into one string
all_parameters <- paste(
    sapply(names(parameters), 
           FUN=function(param_name, parameters) {
               paste(param_name, paste(parameters[[param_name]], collapse=','), collapse='', sep='=')
           }, 
           parameters),
    collapse="&")

# Paste base URL and parameters
requested_url <- paste0(service_url, all_parameters)

# Encode URL (in case there would be any space character for instance)
requested_url <- URLencode(requested_url)

# Start request to service
response <- getURL(requested_url, .opts = list(ssl.verifypeer = FALSE))

return(response)
}


The *apply family of functions are designed to apply FUN to the elements of the object supplied to the respective *apply function.
In your example, the elements to which FUN is applied are the individual elements of names(parameters). sapply() takes the first element, names(parameters)[1] and passes that to FUN as the first argument. Hence param_name is used to refer to names(parameters)[1], then to names(parameters)[2], and so on.
In other words, sapply() arranges to pass, in turn, the elements of sapply()s first argument to FUN supplying these elements as the first argument of FUN.
You can see this more clearly with this simpler example:
sapply(1:10, FUN = function(i) {writeLines(paste("working on", i)); i})

hence i takes on the values 1, 2, ..., 10, in turn and the anonymous function works on each of them:
> sapply(1:10, FUN = function(i) {writeLines(paste("working on", i)); i})
working on 1
working on 2
working on 3
working on 4
working on 5
working on 6
working on 7
working on 8
working on 9
working on 10
 [1]  1  2  3  4  5  6  7  8  9 10


names(parameters) is being passed to param_name. A more basic example: sapply(df1, mean). The implication being sapply(df1, function(x) mean(x)). In this case each element of df1 is being passed to mean as the argument x. The apply functions take the first argument and pass it to the specified function (the second argument of an apply function)
For example:
sapply(mtcars, mean)

       mpg        cyl       disp         hp       drat         wt       qsec 
 20.090625   6.187500 230.721875 146.687500   3.596563   3.217250  17.848750 
        vs         am       gear       carb 
  0.437500   0.406250   3.687500   2.812500 

Also, the sapply() is constructed as sapply(x, FUN,...) the ... is any additional arguments passed to the function FUN. In your example, parametersis being passed as the second argument (names(parameters) is implicitly the first).
