Remove
Remove[s1,s2,…]
removes the symbols si completely, so that their names are no longer recognized by the Wolfram Language.
Remove[patt1,patt2,…]
removes all symbols whose names textually match any of the arbitrary string patterns patti.
Remove[{spec1,spec2,…}]
removes any symbols that are equal to or whose names match any of the speci.
Details
- You can use Remove to get rid of symbols that you do not need, and which may shadow symbols in contexts later on your context path. »
- The pattern patt can be given as a string with metacharacters, as StringExpression[…] or as RegularExpression["regex"]. »
- Remove allows abbreviated string patterns containing the following metacharacters:
-
* match zero or more characters @ match one or more characters, but not uppercase letters - Remove["context`*"] removes all symbols in a particular context. »
- Remove["`*"] removes all symbols in the current context. »
- Once you have removed a symbol, you will never be able to refer to it again, unless you recreate it.
- If you have an expression that contains a symbol that you remove, the removed symbol will be printed as Removed["name"], where its name is given in a string. »
- Remove works with LocalSymbol, CloudSymbol, PersistentSymbol and InitializationValue objects. »
- Remove does not affect symbols with the attributes Locked or Protected. »
- Remove has attribute HoldAll. »
Examples
open allclose allScope (11)
Symbol Inputs (2)
Using Patterns (5)
Specify symbols to remove as string patterns:
Remove all symbols in the current context:
There are no longer any symbols in the current context:
Remove all symbols in a given context:
Remove all 2-character symbols in the current context using StringExpression:
The symbols x1 and x2 were removed, but y remains unaffected:
Remove all 3-character symbols in the current context using RegularExpression:
Applications (1)
Properties & Relations (5)
Remove[pattern] removes the same symbols as Remove/@Names[pattern]:
If a symbol is removed, all of its properties and definitions are removed as well:
Using the same symbol again creates a new one without any of its old properties:
ClearAll also removes all properties and definitions but leaves the symbol intact:
Remove removes the symbol completely:
If an expression still refers to a removed symbol, those places are denoted with Removed:
Possible Issues (3)
Protected symbols cannot be removed:
Use Unprotect to remove protected symbols:
Remove does not affected locked symbols:
When using a pattern without a context mark, all matching symbols on $ContextPath are removed:
The symbol xy was removed, along with attempts to remove several system symbols:
Use a pattern with an explicit context mark to avoid potentially matching symbols from system or other contexts:
Text
Wolfram Research (1988), Remove, Wolfram Language function, https://reference.wolfram.com/language/ref/Remove.html (updated 2022).
CMS
Wolfram Language. 1988. "Remove." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/Remove.html.
APA
Wolfram Language. (1988). Remove. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Remove.html