Skip to contents

This helper function generates a json string containing the data produced by Tabula$get_crosstabs_data(), and which then can be put as the "data" attribute of the <table-charter> app. It is also used by Tabula$save_html_app()

Usage

gen_data_json(l)

Arguments

l

list object generated by Tabula$get_crosstabs_data().

Value

A character string

Examples

df <- tibble::tibble(
  q1 = c(1, 2, 1) |> haven::labelled(c(Yes = 1, No = 2), label = "Super important question"),
  age = c(2, 1, 1) |> haven::labelled(c("18-39" = 1, "40+" = 2), label = "age")
)
mapping_file = list(
  Questions = data.frame(
    Type  = "cat",
    RowVar = "q1",
    Title = "The crosstab's title"
  ),
  Macro = list(ColVar = "age")
)
m <- Tabula$new(df, mapping_file)
m$get_crosstabs_data() |> gen_data_json()
#> [1] "{\"type\":\"table-object\",\"data\":{\"Tab\":{\"BookNo\":[999999999],\"QuestNo\":[\"_row_2\"],\"TabName\":[\"CAT#_row_2@1\"],\"QuestLine\":[2],\"TabNo\":[1],\"TabType\":[\"CAT\"],\"TabTitle\":[\"The crosstab's title\"],\"TabTitle1\":[\"The crosstab's title\"],\"TabTitle2\":[\"The crosstab's title\"],\"TabTitle3\":[\"The crosstab's title\"],\"TabCaption\":[null],\"SelVal\":[null],\"repov_name\":[null],\"TabCount\":[11],\"TabRowTypes\":[null]},\"Val\":{\"BookNo\":[999999999,999999999,999999999,999999999,999999999,999999999,999999999,999999999,999999999,999999999,999999999,999999999,999999999,999999999,999999999,999999999,999999999,999999999,999999999,999999999,999999999],\"QuestNo\":[\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\"],\"TabNo\":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],\"RowNo\":[4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10],\"ColNo\":[4,5,6,4,5,6,4,5,6,4,5,6,4,5,6,4,5,6,4,5,6],\"Value\":[3,2,1,2,1,1,66.6667,50,100,1,1,0,33.3333,50,0,3,2,1,100,100,100]},\"Row\":{\"BookNo\":[999999999,999999999,999999999,999999999,999999999,999999999,999999999,999999999,999999999,999999999,999999999],\"RowNo\":[1,2,3,4,5,6,7,8,9,10,11],\"RowContent\":[\"Title\",\"Header\",\"Header\",\"Total\",\"Detail\",\"Detail\",\"Detail\",\"Detail\",\"Valid\",\"Valid\",\"Empty\"],\"RowAbsPercent\":[\"\",\"\",\"\",\"Abs\",\"Abs\",\"Percent\",\"Abs\",\"Percent\",\"Abs\",\"Percent\",\"\"],\"RowWeighted\":[\"\",\"\",\"\",\"Unweighted\",\"Unweighted\",\"Unweighted\",\"Unweighted\",\"Unweighted\",\"Unweighted\",\"Unweighted\",\"\"],\"TabNo\":[1,1,1,1,1,1,1,1,1,1,1],\"RowTitle1\":[\"The crosstab's title\",null,null,\"TOTAL\",\"Yes\",\"Yes\",\"No\",\"No\",\"VALID CASES\",\"VALID CASES\",\"\"],\"RowTitle2\":[\"\",\"\",\"\",\"TOTAL\",\"Yes\",\"Yes\",\"No\",\"No\",\"VALID CASES\",\"VALID CASES\",\"\"],\"RowTitle3\":[\"\",\"\",\"\",\"abs\",\"abs\",\"in %\",\"abs\",\"in %\",\"abs\",\"in %\",\"\"],\"RowFormat\":[null,null,null,null,null,null,null,null,null,null,null],\"RowDecimals\":[null,null,null,0,0,1,0,1,0,1,null],\"RowVariable\":[null,null,null,\"q1\",\"q1\",\"q1\",\"q1\",\"q1\",\"q1\",\"q1\",null],\"RowValue\":[null,null,null,1,1,1,2,2,1,1,null],\"row_type\":[null,null,null,\"total\",\"detail_freqs_valid\",\"detail_perc_valid\",\"detail_freqs_valid\",\"detail_perc_valid\",\"n_valid_freqs\",\"n_valid_perc\",null],\"QuestNo\":[\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\",\"_row_2\"],\"RowTypeS\":[\"Title\",\"Header\",\"Header\",\"Total|AbsUnweighted\",\"Detail|AbsUnweighted\",\"Detail|PercentUnweighted\",\"Detail|AbsUnweighted\",\"Detail|PercentUnweighted\",\"Valid|AbsUnweighted\",\"Valid|PercentUnweighted\",\"Empty\"],\"RowType\":[1,2,2,2097408,2097168,33554448,2097168,33554448,2097664,33554944,4],\"RowContentDetail\":[\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"]},\"Head\":{\"BookNo\":[999999999,999999999,999999999,999999999,999999999],\"HeadNo\":[1,2,3,4,5],\"HeadName\":[\"DC#ROWHEADER\",\"DC#TOTAL\",\"age@1\",\"DC#EMPTY\",\"DC#TITLE\"],\"HeadTitle\":[null,\"TOTAL\",\"age\",null,null],\"HeadCount\":[3,1,2,1,1]},\"Col\":{\"BookNo\":[999999999,999999999,999999999,999999999,999999999,999999999,999999999,999999999],\"ColNo\":[1,2,3,4,5,6,7,8],\"HeadNo\":[1,1,1,2,3,3,4,5],\"ColTitle1\":[\"\",\"\",\"\",\"TOTAL\",\"age\",\"age\",\"\",\"\"],\"ColTitle2\":[\"\",\"\",\"\",\" \",\"18-39\",\"40+\",\"\",\"\"],\"ColVariable\":[\"DC#ROWHEADER\",\"DC#ROWHEADER\",\"DC#ROWHEADER\",\"DC#TOTAL\",\"age\",\"age\",\"DC#EMPTY\",\"DC#TITLE\"],\"ColValue\":[null,null,null,1,1,2,null,null]}}}"