I have a question regarding highlighting severals values in (column of) a dataset. Here a simple example:

names = StringJoin["name", #] & /@ ToString /@ Range[9];

values = RandomInteger[100, 9];

and then

ds = Dataset[AssociationThread[{"name", "value"} -> #] & /@ ({names, 

Now we have something like:

enter image description here

I now can highlight values in the Dataset with:

    highLight1[x_] := Which[x < 0.9*50, Style[x, Blue],
   x > 1.1*50, Style[x, Red],
   True, x];

Now the following does what I desire, it applies a function to a column of the dataset:

ds[All, {"value" -> highLight1}]

enter image description here

What I could not manage to do is to make the highlighting work with a parameter, something like

    Clear highLight;
highLight[x_, limit_] := Which[x < 0.9*limit, Style[x, Blue],
   x > 1.1*limit, Style[x, Red],
   True, x];

This does not work, even when I use a modified version which accepts a list as x_ in the highlight1 function.

enter image description here

So the question is, whether there is a clean and simple way to get the values highlighted in this "parametrized" way? (Maybe it is just simple and I do not see it...)

  • 6
    $\begingroup$ Just a precedence issue: ds[All, {"value" -> (highLight[#, 50] &)}] $\endgroup$ – Karsten 7. Aug 21 '16 at 18:48
  • $\begingroup$ @Karsten7.: Thank you! You saved my day. It is that simple (shame on me) but I did not see this issue... and then tried a lot of (funny) things ;-) $\endgroup$ – mgamer Aug 21 '16 at 19:19
  • $\begingroup$ reference.wolfram.com/language/ref/Function.html#25791 $\endgroup$ – Karsten 7. Aug 21 '16 at 19:56
  • $\begingroup$ This would be a job for the linter, if Mathematica would have one. $\endgroup$ – Karsten 7. Aug 21 '16 at 21:12

Browse other questions tagged or ask your own question.