Kable etc. require an object that is coercible into a data frame as input. However, the output objects of those functions are not data frames or matrices, but list-like structures, which cannot be coerced into data frames (hence your error). It is not clear from your question which information you want to display from each object, but you can access each attribute using the $
operator, e.g. nmds.bray$points
or betadisp_entero$vectors
.
Edit:
The author has specified that they want to capture specific attributes. To capture any attributes in a tidy table, you can use the following code chunk, provided that you know which attributes you are interested in. You can inspect all attributes of an object using attributes(object)$names
.
I'm assuming that you are using the phyloseq::ordinate
function above, which internally uses vegan::metaMDS
. To see which attributes are printed by print(nmds.bray)
, have a look at the source code on vegan's GitHub page. Likewise, to see which attributes are printed by vegan::betadisper
, check out the source code for the print
statement.
# Returns attribute: value mappings with readable names in a data.frame
tidy_attributes <- function(object, attributes){
# Get the attribute names
if (!is.null(names(attributes))){
atts <- names(attributes)
} else {
atts <- attributes
}
# Store the attribute values in a data frame
df <- data.frame(attribute = atts,
value = unlist(object[atts]))
# Set readable names if names are given
if (!is.null(names(attributes))){
df$attribute <- attributes[df$attribute]
}
return(df)
}
tidy_attributes(object = nmds.bray,
attributes = c("stress" = "Stress",
"nobj" = "Number of objects"))