Blocking Dataset`$ElisionThreshold doesn't work

The resulting Dataset expression is typeset by the front-end after evaluation is complete. This means that the Block expression has already been exited before typesetting occurs. The value of Dataset`$ElisionThreshold is no longer being overridden as the dataset is being rendered.

One way to work around this is to use Print to force the typesetting to occur during evaluation:

ClearAll[ShowDataset2]
ShowDataset2[{assoc__}, query__] := 
    Block[{Dataset`$ElisionThreshold = Length[{assoc}]*4},
        Print @ Dataset[Query[query]@{assoc}]
    ]

This simple work-around comes at a cost: the return value of ShowDataset2 is now Null instead of the dataset.

Usage:

$data = ExampleData[{"Dataset", "Titanic"}] // Normal;

ShowDataset2[$data, All]

dataset screenshot

Beware that the front-end sometimes has difficulty rendering large box structures such as the one in the example above. I saw intermittent rendering glitches as a scrolled through my test notebook (using version 10.3 on Windows 7x64, emphasis on "intermittent").

Update for Version 11

Version 11 introduced a new style of dataset formatting. The variable Dataset`$ElisionThreshold is not used in the new style -- Dataset`$DatasetTargetRowCount is used instead. Alternatively, Dataset`$ElisionThreshold can still be used if we also set Dataset`$UseNewDatasetFormatting = False.

All of this remains undocumented and unsupported behaviour.


You could use an output form:

Unprotect[$OutputForms];
AppendTo[$OutputForms, ShowDataset];
Protect[$OutputForms];

ShowDataset /: MakeBoxes[ShowDataset[ds_Dataset],StandardForm]:=Block[
    {Dataset`$DatasetTargetRowCount = Length[ds]},

    With[{boxes = MakeBoxes[ds]},
        InterpretationBox[
            boxes,
            ds
        ]
    ]
]

For example:

data = Dataset @ RandomReal[1, {25, 2}]

enter image description here

ShowDataset[data]

enter image description here

Head[%]

Dataset

I used an InterpretationBox so that you can copy/paste the output.