16
$\begingroup$

A Dataset with 16 columns or less is shown in a nice way:

Association @@@ 
   Table["col" <> ToString@j -> i j, {i, 10}, {j, 16}] // Dataset

Mathematica graphics

A Dataset with more than 16 columns no.

set = Association @@@ 
   Table["col" <> ToString@j -> i j, {i, 10}, {j, 17}] // Dataset

Mathematica graphics

At this point one can guess a proper subset of these 17 columns is shown in a nice way. Indeed:

set[All, 1 ;; 2]

Mathematica graphics

Wrong guess :) But it's "easy" to improve this appearance:

set[All, 1 ;; 2] // Normal // Dataset

Mathematica graphics

Am'I missing something or there is maybe a super-secret option to control this behavior?

$\endgroup$
5
  • 2
    $\begingroup$ This isn't quite what you want, but you can get a bit of control over how much the Dataset typesetting shows by modifying the variable Dataset`$ElisionThreshold. However, that doesn't help here. The problem is that when going from 16 to 17 columns, the deduced type of the data goes from TypeSystem`Struct to TypeSystem`Assoc, which has different typesetting rules (although it probably should be displayed as nicely, perhaps a minor bug?). $\endgroup$
    – Stefan R
    Commented Apr 28, 2015 at 20:58
  • 1
    $\begingroup$ Note that you can inspect the deduced data type by using Dataset`GetType, e.g. Dataset`GetType[set]. $\endgroup$
    – Stefan R
    Commented Apr 28, 2015 at 21:00
  • 4
    $\begingroup$ Also, Dataset has an undocumented second argument, where you can explicitly specify the type: Dataset[data, type]. So here you could do Dataset[data, TypeSystem`Vector[TypeSystem`Struct[{"col1",...,"col17"}, {TypeSystem`Atom[Integer],....},10]] $\endgroup$
    – Stefan R
    Commented Apr 28, 2015 at 21:04
  • $\begingroup$ This is similar to the question I asked here. In this case the answer is not quite as useful but I think its still a minor improvement on what you have. Basically wrap your selection criteria in braces. set[All, {1 ;; 2}] if we are lucky @Mr.Wizard will be along shortly to improve it ;) $\endgroup$ Commented Apr 28, 2015 at 21:35
  • 2
    $\begingroup$ @StefanR Consider making this an answer - it looks like a good one (to me at least). $\endgroup$ Commented Apr 29, 2015 at 0:03

1 Answer 1

9
$\begingroup$

The general "super-secret option" question was addressed by Stefan R in the comments. This is an answer to the practical problem of easily making a particular dataset show in a nice way.

Actually, it is more of a trick, and one which exploits some of the other new Mathematica machinery: semantic interpretation. It turns out that datasets created from semantically imported data are always nicely formatted, no matter the number of columns. Thus, we can use the old SemanticImportString-ExportString routine to get a proper display:

displaydataset[dataset_] := With[
   {import = SemanticImportString[
      ExportString[ Join[{Normal@dataset[1, Keys]}, Normal@dataset[Values]], "CSV"], 
      Automatic, "Dataset"]},
   import[All, AssociationThread[Normal@dataset[1, Keys], Normal@import[1, Keys]]]
   ];

The extra structure in the last line replaces the imported keys with the old keys - imported keys come in garbled if they have any special symbols (like greek letters) in them. The rest of the data should, in most cases, be handled well by the interpreter.

With

set = Association @@@ Table["col" <> ToString@j -> i j, {i, 10}, {j, 17}] // Dataset

set

we get

displaydataset@set

dataset

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.