10
$\begingroup$

Mathematica 12 on wolfram cloud isn't rendering the table for an association of lists. According to the documentation you should be able to make columns in the table by: using an association of lists

However I tried this

$Version thing2 = Dataset[<|"apple" ->{fruit,sweet},"carrot" -> {vegetable,crunchy}|>] 

and instead it returned:

table without separated columns

Why is this?

$\endgroup$
2
  • 1
    $\begingroup$ Don't know why it's not working. This workaround gives you the rendering you want: Dataset[{<|"apple" -> fruit, "carrot" -> vegetable|>, {sweet, crunchy}}]. But I don't know if this syntax will interfere with operations on the association. $\endgroup$ Commented May 15, 2021 at 21:12
  • 1
    $\begingroup$ That looks like a documentation error. You should report it. $\endgroup$ Commented May 16, 2021 at 1:50

2 Answers 2

11
$\begingroup$

Short Version

Dataset layouts are generated from complex heuristics aimed at maximizing interactive usability rather than static layout predictability. The heuristics change between releases making it difficult, and sometimes impossible, to force a particular static layout.

Long Version

A long-standing criticism of Dataset is that its operation is driven heavily by heuristics and those heuristics can seem quite arbitrary at times. The present question provides an example.

In this case, the layout algorithm is trying to decide how best to utilize space to render the data. It is triggering off the number of elements in each row. For up to four elements, version 12.1 renders each row as a list within a single cell:

With[{data = ConstantArray["x", 4]}, Dataset[<|"a" -> data, "b" -> data|>]] 

rows rendered as lists

For between five and eight elements, each row is rendered as a vertical block of cells:

With[{data = ConstantArray["x", 5]}, Dataset[<|"a" -> data, "b" -> data|>]] 

rows rendered as a column of cells

Only when rows have nine or more elements do we see the layout shown in the documentation:

With[{data = ConstantArray["x", 9]}, Dataset[<|"a" -> data, "b" -> data|>]] 

rows rendered as rows

In general, the heuristics which govern layout are complex and take many factors into account. Those factors include object length, object type, whether objects in collection are all of the same type, rendering space available and more. Furthermore, these heuristics change between releases. So even when a work-around is found that generates a particular look there is no guarantee that the next release (or even paclet update) will disturb it.

Editorial Comment

I think that Dataset was designed for ad hoc interactive use, not as a means to generate static layouts with particular forms. Rather, the goal was to allow the user to be able to view and drill into any data structure no matter how complex or large it was. The heuristics are trying to maximize interactive (not static) usability by deciding when to pivot, spread, elide or permit drill-down into data. They do not always guess correctly.

The documentation is silent on this issue which only adds to the frustration when we get an unexpected layout. Perhaps it ought to acknowledge this situation under Possible Issues and mention more predictable static layout alternatives like Grid, TableForm or TableView.

$\endgroup$
7
$\begingroup$

To reiterate what has been mentioned in the comments, this seems to be an issue with the documentation. Please, report this to Wolfram Support. Here is how this can be done while staying within an Association:

$Version thing2 = Dataset[<|"apple" ->{{fruit,sweet}},"carrot" ->{{vegetable,crunchy}}|>] 

This returns:

image of the output for the above code block

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.