Oops, sorry, I misunderstood.
library(rray)
mm <- matrix(rep(0, 9), nrow = 3)
mm
#> [,1] [,2] [,3]
#> [1,] 0 0 0
#> [2,] 0 0 0
#> [3,] 0 0 0
diag(mm) <- 2
mm <- rray_flip(mm, 1)
mm
#> [,1] [,2] [,3]
#> [1,] 0 0 2
#> [2,] 0 2 0
#> [3,] 2 0 0
There has to be an easier way to do this, but this works.