1

I am trying to save some plots. But the syntax below gives me Part, Set and FilterRules errors.

teste4 := Return[Plot[ x, {x, 0, 10}]]; Export["/Users/tomasalvim/Desktop/teste.png", teste4]

Does anyone know what the correct syntax should be to save the plot inside the Return[]?

Error: ""Part specification $Failed[[3,2]] is longer than depth of object""

Thank you in advance

1 Answers1

3

You don't need Return . Also, no need for SetDelayed (:=) in this case.

Export[
    FileNameJoin[{$HomeDirectory,"test.png"}]
    , Plot[ x, {x, 0, 10}]
    , "PNG"
] // SystemOpen

Also, the error you quote doesn't come from that command. Try using a fresh kernel. Read here for different strategies to get a clean Kernel.

rhermans
  • 36,518
  • 4
  • 57
  • 149
  • Thank you for the example, but I don't think it will do. I was trying to go for a minimal working example of the problem, the real function has 10+ arguments, and a Module[]. By the way I am exporting works SOME of the times. Other times I think it forces the kernel to quit, but I'm not sure that is the cause. – Tomás Alvim Feb 20 '23 at 11:16
  • 3
    @TomásAlvim Well, your example does not show the problem. We can only answer yo what you show us. – rhermans Feb 20 '23 at 11:17
  • You are right, in that the error does not come from that command. I'm not sure where it is coming from. I can't clear all the notebook because NDSolve takes too long to evaluate. – Tomás Alvim Feb 20 '23 at 11:23
  • 1
    @TomásAlvim you can DumpSave the output of the slow calculation, restart the Kernel, and then Get the saved file again. Also, try using Echo[expr, "Label", Head] or similar to debug intermediate steps. Somewhere you are getting a $Failed. Furthermore, use scoping and other techniques to avoid lingering definitions. – rhermans Feb 20 '23 at 11:32
  • The DumpSave will save me loads of time, thanks. – Tomás Alvim Feb 20 '23 at 11:44