From hb at biostat.ucsf.edu  Fri Oct 24 05:10:19 2014
From: hb at biostat.ucsf.edu (Henrik Bengtsson)
Date: Thu, 23 Oct 2014 20:10:19 -0700
Subject: [Rd] No error when assigning values to an "empty"
	vector/matrix/array
Message-ID: <CAFDcVCQWWDvfSmiapMWBJ75WmMzyAMYsndmJaJp1r=-uzG7yXQ@mail.gmail.com>

Assigning one or more values to a vector/matrix/array x for which
length(x) == 0 gives no error, e.g.

> x <- integer(0)
> x[] <- 1:2

> x <- matrix(nrow=0, ncol=1)
> x[] <- 1:2
> x[,1] <- 1:2

> x <- array(dim=c(0,1,1))
> x[] <- 1:2
> x[,1,1] <- 1:2

whereas

> x <- integer(1)
> x[] <- 1:2
Warning message:
In x[] <- 1:2 :
  number of items to replace is not a multiple of replacement length
> x <- matrix(nrow=1, ncol=1)
> x[] <- 1:2
Warning message:
In x[] <- 1:2 :
  number of items to replace is not a multiple of replacement length
> x[,1] <- 1:2
Error in x[, 1] <- 1:2 :
  number of items to replace is not a multiple of replacement length
> x <- array(dim=c(1,1,1))
> x[] <- 1:2
Warning message:
In x[] <- 1:2 :
  number of items to replace is not a multiple of replacement length
> x[,1,1] <- 1:2
Error in x[, 1, 1] <- 1:2 :
  number of items to replace is not a multiple of replacement length

Is this intended by design or is it a bug that should be reported?

/Henrik



[Rd] No error when assigning values to an "empty" vector/matrix/array
Henrik Bengtsson