0

I am trying to do the following, where num.mat is supposed to be a matrix populated with numeric values.

measurements <<- read.csv(input$Data$datapath, check.names = 
F, row.names = 1)
num.mat <<- suppressWarnings(apply(measurements, 2, 
as.numeric))
DT::datatable(head(num.mat,20),
              options = list(scrollX=TRUE))

Doing:

class(num.mat)

Does indeed return:

[1] "matrix" "array"

I am not sure why when I try to run the code I get the following error message in my R Shiny app (but it could very well be a different problem):

cannot coerce class c("datatables", "htmlwidget") to a data.frame

Any ideas would be much appreciated!

Edit: Sorry for not providing more detail in my first post, I have tried to add more context now. I am new to SO and R/RShiny so please tell me if I am still not asking my question correctly. Thank you so much!

  • I cannot reproduce your error with matrices of `logical`, `integer`, `numeric`, `complex`, or `character`, so either your matrix is something else, or there is something outside of this line of code that is contributing to the error. I think it would help if you provided a reproducible example, some good references for this include: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. Welcome to SO! – r2evans Nov 16 '20 at 17:06
  • (For instance, does `class(num.mat)` return `[1] "matrix" "array"`? In what bigger context is this code running? Please [edit] your question with more details. Thank you!) – r2evans Nov 16 '20 at 17:07
  • Please add a MRE. Your error sounds like you try to convert the resulting `datatables` object into a data.frame at some other part of your code which does not work – starja Nov 16 '20 at 19:02

0 Answers0