format_latte() formats a matrix in latte's style. write_latte() writes a latte-formatted file to file. read_latte() reads a latte-formatted file from disk.

format_latte(mat, file)

write_latte(mat, file)

write.latte(mat, file)

read_latte(file, format = c("mat", "Ab"))

read.latte(file, format = c("mat", "Ab"))

Arguments

mat

A matrix

file

A filename

format

"mat" or "Ab"

Value

  • format_latte() -- A character string of the matrix in latte format.

  • write_latte() -- An invisible character string of the formatted output.

  • read_latte() -- An integer matrix.

Examples

(mat <- matrix(sample(9), 3, 3))
#> [,1] [,2] [,3] #> [1,] 9 2 7 #> [2,] 5 8 4 #> [3,] 3 6 1
format_latte(mat)
#> [1] "3 3\n9 2 7\n5 8 4\n3 6 1"
cat(format_latte(mat))
#> 3 3 #> 9 2 7 #> 5 8 4 #> 3 6 1
(file <- file.path(tempdir(), "foo.hrep"))
#> [1] "/var/folders/r3/126_d6t55f5d32tplbg5mk1d0c48s9/T//RtmpugrA1n/foo.hrep"
write_latte(mat, file) file.show(file) read_latte(file)
#> [,1] [,2] [,3] #> [1,] 9 2 7 #> [2,] 5 8 4 #> [3,] 3 6 1
read_latte(file, "Ab")
#> $A #> [,1] [,2] #> [1,] -2 -7 #> [2,] -8 -4 #> [3,] -6 -1 #> #> $b #> [1] 9 5 3 #>
attr(mat, "linearity") <- c(1, 3) attr(mat, "nonnegative") <- 2 mat
#> [,1] [,2] [,3] #> [1,] 9 2 7 #> [2,] 5 8 4 #> [3,] 3 6 1 #> attr(,"linearity") #> [1] 1 3 #> attr(,"nonnegative") #> [1] 2
format_latte(mat)
#> [1] "3 3\n9 2 7\n5 8 4\n3 6 1\nlinearity 2 1 3\nnonnegative 1 2"
cat(format_latte(mat))
#> 3 3 #> 9 2 7 #> 5 8 4 #> 3 6 1 #> linearity 2 1 3 #> nonnegative 1 2
write_latte(mat, file) file.show(file) read_latte(file)
#> [,1] [,2] [,3] #> [1,] 9 2 7 #> [2,] 5 8 4 #> [3,] 3 6 1 #> attr(,"linearity") #> [1] 1 3 #> attr(,"nonnegative") #> [1] 2
#> [1] TRUE