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
  • 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.
    Commented Jun 26, 2018 at 15:22
  • 1
    $\begingroup$ you can also do: showResults[list_, opts : OptionsPattern[GraphicsRow]] := GraphicsRow[list, opts] $\endgroup$
    – kglr
    Commented Jun 27, 2018 at 4:36

1 Answer 1

6
$\begingroup$

This will do:

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

showResults[{1, 1}]
$\endgroup$
4
  • $\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$ Commented Jun 26, 2018 at 10:25
  • $\begingroup$ Thanks, Rolf. This is indeed a solution to my problem, but what is exactly wrong with my definition? $\endgroup$ Commented Jun 26, 2018 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$ Commented Jun 26, 2018 at 10:32
  • 1
    $\begingroup$ @OlegSoloviev Nothing wrong with your solution. The implementation of GraphicsRow is buggy. You could submit the problem to [email protected]. $\endgroup$ Commented Jun 26, 2018 at 10:35

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.