ellipsis (...) used in false context

I have the below function:

sendMessage <- function(id, code, param = list(...)){
  message <- list(id = id, code=code, param = param)
}

The function works fine if I add parameters to the list:

message <- sendMessage(id = "test", code="warning", param = list(param1 = "Hello", param2 = "Bye"))

But If I do not pass any parameters I get an error:

message <- sendMessage(id = "test", code="warning")

Error in sendMessage(id = "test", code = "warning") : 
  '...' used in wrong context

How can I send a message if I do not want to pass any parameters?

Hi @noveld,

I think either one of these should be fine:

sendMessage <- function(id, code, ...){
  param <- list(...)
  message <- list(id = id, code = code, param = param)
}
# or

sendMessage <- function(id, code, param = list()){
  message <- list(id = id, code = code, param = param)
}

Thanks a lot! I was overthinking this way to much :laughing:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.