Pipe friendly dim<-()
, with option to pad to necessary length. Also allows
for filling the array using C style row-major semantics.
set_dim( x, new_dim, pad = getOption("listarrays.autopad_arrays_with", NULL), order = c("F", "C"), verbose = getOption("verbose") )
x | A vector or array to set dimensions on |
---|---|
new_dim | The desired dimensions (an integer(ish) vector) |
pad | The value to pad the vector with. |
order | whether to use row-major (C) or column major (F) style
semantics. The default, "F", corresponds to the default behavior of R's
|
verbose | Whether to emit a message if padding. By default, |
Object with dimensions set
set_dim2()
, `dim<-`()
, reticulate::array_reshape()
#> [,1] [,2] [,3] [,4] [,5] #> [1,] 1 3 5 7 9 #> [2,] 2 4 6 8 10#> Error in dim(x) <- new_dim : #> dims [product 10] do not match the length of object [7]#> [,1] [,2] [,3] [,4] [,5] #> [1,] 1 3 5 7 99 #> [2,] 2 4 6 99 99#> [,1] [,2] [,3] [,4] [,5] #> [1,] 1 2 3 4 5 #> [2,] 6 7 99 99 99#> [,1] [,2] #> [1,] 1 3 #> [2,] 2 4#> [,1] [,2] #> [1,] 1 2 #> [2,] 3 4#> [1] TRUE#> [1] TRUEif (FALSE) { py_reshaped <- reticulate::array_reshape(1:4, c(2,2)) storage.mode(py_reshaped) <- "integer" # reticulate coerces to double identical(y, py_reshaped) # if needed, see listarrays:::array_reshape() for # a drop-in pure R replacement for reticulate::array_reshape() }