3
$\begingroup$

How can I ClearAll variables and tables, except a table of data? Suppose the data table is WRR.

WRR = Table[WRR[i] = Last[m[i] /. aRR], {i, 10}];

I am looking for something like:

Protect[WRR]; ClearAll...

But this removes WRR too!

$\endgroup$
2
  • 2
    $\begingroup$ How could it work, ClearAll alone does not do anything. Does this work: (ClearAll["Global`*"]; WRR = #) &@WWR? $\endgroup$
    – Kuba
    May 11, 2017 at 7:41
  • 2
    $\begingroup$ ClearAll @@ Cases[Names["Global*"], Except["WRR"]]` $\endgroup$
    – LouisB
    May 11, 2017 at 7:51

2 Answers 2

3
$\begingroup$

I think the attribute you are looking for is Locked.

WRR = Range[10];
x = 5;

SetAttributes[WRR, Locked];

Now:

ClearAll["Global`*"]

x

WRR

ClearAll::locked: Symbol WRR is locked. >>

x

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

You can still redefine WRR as it is not Protected:

WRR = {11, 12, 13};

WRR
{11, 12, 13}

To clear its definition use Unset:

WRR =.;

WRR
WRR
$\endgroup$
1
$\begingroup$

As suggested in comments:

(ClearAll["Global`*"]; WRR = #) & @ WWR

or

ClearAll @@ Cases[Names["Global`*"], Except["WRR"]]

or

ClearAll @@ DeleteCases[Names["Global`*"], "WRR"]

etc.

$\endgroup$

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.