Do.call () doesn't like the basic "c" combo function

I have a large section of code, but I've narrowed the problem down to this - So I want to return a merged list.

do.call(c,"X")
Error in do.call(c, "X") : second argument must be a list

      

So, above, it complains that the SECOND argument is not a list.

asimplelist=list(2,3,4)
class(asimplelist)
[1] "list"
do.call(c,asimplelist)
Error in do.call(c, asimplelist) : 
'what' must be a function or character string

      

Why doesn't this return a concatenated list? C is a legal function and is passed a list?

args(do.call)
function (what, args, quote = FALSE, envir = parent.frame()) 
NULL 

      

So "what" is the function argument it is complaining about.

+2


source to share


1 answer


I will reply by "steal" my answer from this comment from Nick Kennedy :

Better to put it c

in double quotes.

If the user has a named nonfunction c

in the global environment, it do.call(c, dates)

will fail "Error in do.call(c, list(1:3)) : 'what' must be a character string or a function"

.



It is clear that this may not be the best practice to define c

, but it is quite common for people to do so a <- 1; b <- 2; c <- 3

.

For most purposes, R still works fine in this scenario; c(1, 2)

will work but do.call(c, x)

won't.

Of course, if the user has overridden c

as a function (for example c <- sum

), then the do.call

overridden function will be used.

+2


source







All Articles