Closed RobinHankin closed 5 years ago
Ironically the difficult part of the fix, wherein apply()
is replaced with lapply()
is unnecessry because the code only broke when n==length(v)
and this case is caught on the second line which, as it says in its own comment, is unnecessary.
Bug in
multiset()
. Argumentn
should give the number of rows of the output matrix butmultiset()
fails if the user specifiesn=length(v)
(which should be the default):To see the problem, look at the following code. In the function, the output of
apply()
is sent tocbind()
bydo.call()
:But look what happens if
n <- 4
:This is because
apply()
is simplifying its output, as documented: "If each call toFUN
returns a vector of lengthn
, then ‘apply’ returns an array of dimensionc(n, dim(X)[MARGIN])
ifn > 1
".Here is a simpler example:
On R-devel, Brian Ripley said: "you seem to want a list result from
apply()
. If that is what you want, why not uselapply()
? E.g.is the list equivalent of
apply(m, 1, max)
.