elle
elle

Reputation: 31

Javascript error using DT package in RStudio

This is my first post, and I'm probably doing something silly to create this error ... I am running R 4.2.1 in RStudio, version 2022.07.1, built 554 ("Spotted Wakerobin"). Using a built-in dataset, here is a reproducible example:

table(esoph$agegp, esoph$alcgp, dnn = c("age", "alc")) |>
  DT::datatable(
    options = list(
      scrollY = FALSE)
  )

I am getting a Javascript Alert. In case the image doesn't appear, it says,

DataTables warning: table id=DataTables_Table_0 - Requested unknown parameter '4' for row 0, column 4. For more information about this error, please see http://datatables.net/tn/4

I read that page, and I wonder if it means there is a combination of values that does not exist in the dataset. Appreciate any help. Thank you.

enter image description here

Upvotes: 2

Views: 147

Answers (1)

elle
elle

Reputation: 31

I asked a work colleague about this problem, and she came up with this solution: Converting the table to a data frame, then pivoting wider:

table(agegp = esoph$agegp, alcgp = esoph$alcgp) |> 
  as.data.frame() |> 
  tidyr::pivot_wider(names_from = alcgp, values_from = Freq) |> 
  DT::datatable(options = list(scrollY = FALSE))

Thank you to all who replied.

Upvotes: 1

Related Questions