Benjamin Tyner
2019-May-31 13:25 UTC
[R] Matrix::bdiag doesn't like being given a single named argument
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
Jeff Newmiller
2019-May-31 14:05 UTC
[R] Matrix::bdiag doesn't like being given a single named argument
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 at 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 at 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.