[Rd] diag() when input is a numeric scalar

philchalmers rphilip.chalmers at gmail.com
Thu May 2 01:35:16 CEST 2013


Hi All,

I'm wondering why when passing a single numeric value that contains any
decimals to diag() that the value is silently coerced to a integer for
constructing an identify matrix. To me, an input like diag(5.435) seems
fairly ambiguous and is more than likely a programming mistake, since it's
not obvious that a 5x5 identity matrix should be created. I've seen some
code where other writers have been burned on this as well, especially when
trying extract diagonal elements but forget about the scalar case. A warning
or message would help track this problem down really quickly to force the
author to use diag(floor(5.435)) explicitly, if indeed that is there
intention. Thoughts?

Phil



--
View this message in context: http://r.789695.n4.nabble.com/diag-when-input-is-a-numeric-scalar-tp4665986.html
Sent from the R devel mailing list archive at Nabble.com.



More information about the R-devel mailing list