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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Benjamin Tyner
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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Matrix::bdiag doesn't like being given a single named argument

Jeff Newmiller
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 <[hidden email]> 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
>
>______________________________________________
>[hidden email] 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.

______________________________________________
[hidden email] 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.