[R] Matrix::bdiag doesn't like being given a single named argument

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Fri May 31 16:05:02 CEST 2019


My take would be that there is no reason to specify argument names at all when calling bdiag, and clearly there is a reason to not do so.

The error seems to arise from using the S3 method is.list, which allows your final example to work. is.list(a=1) clearly fails to match the x argument, but is.list(list(a=1)) works just fine.

On May 31, 2019 6:25:19 AM PDT, Benjamin Tyner <btyner using gmail.com> wrote:
>Hello,
>
>Perhaps not a bug, but interesting because the error only happens when 
>there is a single named argument.
>
>    > m <- matrix(1, 1, 1)
>    > library(Matrix)
>    > bdiag(m)
>    1 x 1 sparse Matrix of class "dgCMatrix"
>
>    [1,] 1
>    > bdiag(a = m)
>   Error in is.list(...) : supplied argument name 'a' does not match
>'x'
>    > bdiag(a = m, b = m)
>    2 x 2 sparse Matrix of class "dgCMatrix"
>
>    [1,] 1 .
>    [2,] . 1
>
>Moreover, this works fine:
>
>    > bdiag(list(a = m))
>    1 x 1 sparse Matrix of class "dgCMatrix"
>
>    [1,] 1
>
>Thoughts?
>
>Regards
>
>Ben
>
>______________________________________________
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.



More information about the R-help mailing list