6
$\begingroup$

I'm trying to pass the options to a simple function based on GraphicsRow as in the example below, but I get a long list of errors.

showResults[list_, opts : OptionsPattern[]] := 
      GraphicsRow[list,  FilterRules[{opts}, Options[GraphicsRow]]]

showResults[{1, 1}]

I cannot spot any error in the syntax of my function. Is it a bug?

I'm using MMA 11.3 on Windows 10.

$\endgroup$
  • 2
    $\begingroup$ The cause of the bug is that GraphicsRow can take a second argument, spacing, which can be a List. So the empty list returned by FilterRules gets interpreted as spacings, and the internal code fails very poorly when it isn't the right shape. $\endgroup$ – Jason B. Jun 26 '18 at 15:22
  • 1
    $\begingroup$ you can also do: showResults[list_, opts : OptionsPattern[GraphicsRow]] := GraphicsRow[list, opts] $\endgroup$ – kglr Jun 27 '18 at 4:36
6
$\begingroup$

This will do:

showResults[list_, opts : OptionsPattern[ImageSize -> 444]] := 
     GraphicsRow[list, Sequence @@ FilterRules[{opts}, Options[GraphicsRow]]]

showResults[{1, 1}]
$\endgroup$
  • $\begingroup$ And yes, the Option (passing and filtering) mechanism in Mathematica is pretty inconvenient. There are rumors the whole language is being redesigned (because of the new Compiler). So let's hope things will improve then finally. $\endgroup$ – Rolf Mertig Jun 26 '18 at 10:25
  • $\begingroup$ Thanks, Rolf. This is indeed a solution to my problem, but what is exactly wrong with my definition? $\endgroup$ – Oleg Soloviev Jun 26 '18 at 10:28
  • 2
    $\begingroup$ @OlegSoloviev The problem was that you submitted a list of rules insead of a sequence of rules to GraphicsRow. Some built-in functions allow for that; others do not. $\endgroup$ – Henrik Schumacher Jun 26 '18 at 10:32
  • 1
    $\begingroup$ @OlegSoloviev Nothing wrong with your solution. The implementation of GraphicsRow is buggy. You could submit the problem to support@wolfram.com. $\endgroup$ – Rolf Mertig Jun 26 '18 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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