From m@ech|er @end|ng |rom @t@t@m@th@ethz@ch  Mon Feb  1 10:08:14 2021
From: m@ech|er @end|ng |rom @t@t@m@th@ethz@ch (Martin Maechler)
Date: Mon, 1 Feb 2021 10:08:14 +0100
Subject: [Rd] surprised matrix (1:256, 8, 8) doesn't cause error/warning
In-Reply-To: <CAB8pepzJtA0k+xwucuPgsX1U5YJSymy2eX5+XMvi=po5UGmJHw@mail.gmail.com>
References: <CAB8pepzJtA0k+xwucuPgsX1U5YJSymy2eX5+XMvi=po5UGmJHw@mail.gmail.com>
Message-ID: <24599.50430.981659.510862@stat.math.ethz.ch>

>>>>> Abby Spurdle (/??bi/) 
>>>>>     on Mon, 1 Feb 2021 19:50:32 +1300 writes:

    > I'm a little surprised that the following doesn't trigger an error or a warning.
    > matrix (1:256, 8, 8)

    > The help file says that the main argument is recycled, if it's too short.
    > But doesn't say what happens if it's too long.

It's somewhat subtler than one may assume :

> matrix(1:9, 2,3)
     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6
Warning message:
In matrix(1:9, 2, 3) :
  data length [9] is not a sub-multiple or multiple of the number of rows [2]

> matrix(1:8, 2,3)
     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6
Warning message:
In matrix(1:8, 2, 3) :
  data length [8] is not a sub-multiple or multiple of the number of columns [3]

> matrix(1:12, 2,3)
     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6
>

So it looks to me the current behavior is quite on purpose.
Are you sure it's not documented at all when reading the docs
carefully?  (I did *not*, just now).



[Rd] surprised matrix (1:256, 8, 8) doesn't cause error/warning
Martin Maechler