3
$\begingroup$

I have a function someFunction[] that takes a long time to evaluate. I would like to run

{time, result} = Timing@someFunction[];

to also measure the execution time. Instead, I forgot to include Timing@ and wrote

{time, result} = someFunction[];

This ran for a long time, but right at the end when the value was supposed to be assigned a "Set: Lists {time, result} and <<1>> are not the same shape." error was thrown, and I got nothing out. Is there a way to still recover the result of the computation? It would be a shame if there wasn't - the result was already computed, and just the assignment failed.

$\endgroup$
3
  • 1
    $\begingroup$ in 11.2 there should be a menu next to the error message with a "show stack" item. $\endgroup$
    – Kuba
    Commented Jan 25, 2018 at 18:22
  • $\begingroup$ Hm, strange, thought of it as well, but when I was looking for it when I had the error and I swear it wasn't there. Are there cases where "Show Stack" doesn't appear in the pop-up? $\endgroup$
    – Stan
    Commented Jan 25, 2018 at 19:45
  • $\begingroup$ Just a side note, I always prefer to do something like timing = AbsoluteTiming[ result = someFunction[] ]; $\endgroup$
    – Jason B.
    Commented Jan 25, 2018 at 22:18

1 Answer 1

3
$\begingroup$

From my comment:

$Line=0;
{a, b} = (Pause[1]; 10);

Out[1]

Set::shape: Lists {a,b} and 10 are not the same shape.

10

$\endgroup$
3
  • $\begingroup$ Hi Carl, that's true, however, if the output of the function is long then parts of it are shortened to <<1>> and you can't copy-paste them any more. $\endgroup$
    – Stan
    Commented Jan 25, 2018 at 19:40
  • $\begingroup$ @Stan I don't understand. Out[n] always contains the full output, it does not contain any shorteners. $\endgroup$
    – Carl Woll
    Commented Jan 25, 2018 at 19:49
  • $\begingroup$ Hi Carl, sorry, I misread your reply. That's interesting - no "Out" cell is produced, but it's still created behind the scenes, and it contains the output I'm looking for. That's good to know. Thanks! $\endgroup$
    – Stan
    Commented Jan 25, 2018 at 20:13

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.