Re: [Rd] diag(-1) produces weird result

2018-09-18 Thread Gábor Csárdi
Some languages that recognized early design mistakes introduced a strict mode, which applies to a local context, and enforces a safer, more consistent API. This is a pragmatic solution, as it does not require any changes to existing code, but still allows writing better code in the future. Impleme

Re: [Rd] diag(-1) produces weird result

2018-09-18 Thread peter dalgaard
Yes, both are rooted in age-old design infelicities (in which, basically, interactive expedience has taken precedence over consistency and generality). Unfortunately, they are quite difficult to rectify, because there are bound to be countless uses of, say, diag(5) as a 5x5 identity matrix whic

Re: [Rd] diag(-1) produces weird result

2018-09-17 Thread Ravi Varadhan
ptember 17, 2018 12:22:31 PM To: li...@revelle.net Cc: r-devel Subject: Re: [Rd] diag(-1) produces weird result I would say it is a mis-feature. If the 'x' argument of diag() is a vector of length 1, then it creates an identity matrix of that size, instead of creating a 1x1 matrix with the gi

Re: [Rd] diag(-1) produces weird result

2018-09-17 Thread Barry Rowlingson
On Mon, Sep 17, 2018 at 5:22 PM, Gábor Csárdi wrote: > I would say it is a mis-feature. If the 'x' argument of diag() is a > vector of length 1, then it creates an identity matrix of that size, > instead of creating a 1x1 matrix with the given value: > > ❯ diag(3) > [,1] [,2] [,3] > [1,]

Re: [Rd] diag(-1) produces weird result

2018-09-17 Thread Duncan Murdoch
On 17/09/2018 12:14 PM, William Revelle wrote: Dear list A strange bug in the psych package is due to the behavior of the diag function: It gives the expected values for 1, a vector (-1,1), but not for -1 Is this a known feature? It is pretty clearly documented: "diag has four distinct usag

Re: [Rd] diag(-1) produces weird result

2018-09-17 Thread Gábor Csárdi
I would say it is a mis-feature. If the 'x' argument of diag() is a vector of length 1, then it creates an identity matrix of that size, instead of creating a 1x1 matrix with the given value: ❯ diag(3) [,1] [,2] [,3] [1,]100 [2,]010 [3,]001 Of course this

[Rd] diag(-1) produces weird result

2018-09-17 Thread William Revelle
Dear list A strange bug in the psych package is due to the behavior of the diag function: It gives the expected values for 1, a vector (-1,1), but not for -1 Is this a known feature? > diag(1) [,1] [1,]1 > diag(c(-1,1)) [,1] [,2] [1,] -10 [2,]01 > diag(-1) Error in