Try to transform an R object to a format supported by the posterior package.
Value
If possible, a draws object in the closest supported format to x.
The formats are linked to in the See Also section below.
Details
The class "draws" is the parent class of all supported formats,
which also have their own subclasses of the form "draws_{format}" (e.g.
"draws_array").
See also
Other formats:
draws_array(),
draws_df(),
draws_list(),
draws_matrix(),
draws_rvars()
Examples
# create some random draws
x <- matrix(rnorm(30), nrow = 10)
colnames(x) <- c("a", "b", "c")
str(x)
#> num [1:10, 1:3] -0.963 -0.814 -0.195 1.916 0.702 ...
#> - attr(*, "dimnames")=List of 2
#> ..$ : NULL
#> ..$ : chr [1:3] "a" "b" "c"
# transform to a draws object
y <- as_draws(x)
str(y)
#> 'draws_matrix' num [1:10, 1:3] -0.963 -0.814 -0.195 1.916 0.702 ...
#> - attr(*, "dimnames")=List of 2
#> ..$ draw : chr [1:10] "1" "2" "3" "4" ...
#> ..$ variable: chr [1:3] "a" "b" "c"
#> - attr(*, "nchains")= int 1
# remove the draws classes from the object
class(y) <- class(y)[-(1:2)]
str(y)
#> num [1:10, 1:3] -0.963 -0.814 -0.195 1.916 0.702 ...
#> - attr(*, "dimnames")=List of 2
#> ..$ draw : chr [1:10] "1" "2" "3" "4" ...
#> ..$ variable: chr [1:3] "a" "b" "c"
#> - attr(*, "nchains")= int 1