A function factory to read matrix with given number of columns from a file. The matrix is read row-wise (with byrow = TRUE).

read_matrix(ncol)

Arguments

ncol

integer, expected number of columns, passed to base::matrix().

Value

function with 1 argument: file

Examples

m <- matrix(1:6, ncol = 3) tf <- tempfile() write(t(m), file = tf, ncolumns = 3) rm3 <- read_matrix(ncol = 3) rm3(tf)
#> [,1] [,2] [,3] #> [1,] 1 3 5 #> [2,] 2 4 6