<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://bradleymonk.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Custom_R_Functions</id>
	<title>Custom R Functions - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://bradleymonk.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Custom_R_Functions"/>
	<link rel="alternate" type="text/html" href="https://bradleymonk.com/wiki/index.php?title=Custom_R_Functions&amp;action=history"/>
	<updated>2026-04-09T21:18:56Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://bradleymonk.com/wiki/index.php?title=Custom_R_Functions&amp;diff=4027&amp;oldid=prev</id>
		<title>Bradley Monk at 04:37, 12 April 2021</title>
		<link rel="alternate" type="text/html" href="https://bradleymonk.com/wiki/index.php?title=Custom_R_Functions&amp;diff=4027&amp;oldid=prev"/>
		<updated>2021-04-12T04:37:28Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 21:37, 11 April 2021&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l29&quot;&gt;Line 29:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 29:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     rx(c(&amp;quot;j&amp;quot;,&amp;quot;k&amp;quot;))&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     rx(c(&amp;quot;j&amp;quot;,&amp;quot;k&amp;quot;))&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;this &lt;/del&gt;will clear&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Calling &amp;lt;code&amp;gt;rx()&amp;lt;/code&amp;gt; &lt;/ins&gt;will clear &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;all variables from the workspace except for variables &amp;lt;code&amp;gt;j&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Bradley Monk</name></author>
	</entry>
	<entry>
		<id>https://bradleymonk.com/wiki/index.php?title=Custom_R_Functions&amp;diff=4026&amp;oldid=prev</id>
		<title>Bradley Monk: Created page with &quot;Custom R Programming Language Functions   ==Clear All Variables From Workspace Except==  MATLAB has a built-in method to clear all variables from the current workspace environ...&quot;</title>
		<link rel="alternate" type="text/html" href="https://bradleymonk.com/wiki/index.php?title=Custom_R_Functions&amp;diff=4026&amp;oldid=prev"/>
		<updated>2021-04-12T04:34:57Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Custom R Programming Language Functions   ==Clear All Variables From Workspace Except==  MATLAB has a built-in method to clear all variables from the current workspace environ...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Custom R Programming Language Functions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Clear All Variables From Workspace Except==&lt;br /&gt;
&lt;br /&gt;
MATLAB has a built-in method to clear all variables from the current workspace environment, except for one or more specified variables. This can be done simply by typing...&lt;br /&gt;
&lt;br /&gt;
    &amp;gt;&amp;gt; -clearvars except VAR1 VAR2 ETC&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;ve created the following function to perform the same operation in R...&lt;br /&gt;
&lt;br /&gt;
    &amp;gt; rx&amp;lt;-function(S){rm(list=setdiff(ls(.GlobalEnv),c(&amp;quot;rx&amp;quot;,S)),envir=.GlobalEnv)}&lt;br /&gt;
&lt;br /&gt;
This function can be inserted near the top of a script, and evaluated for (re)use later on in the script. This will allow the user to clear all environmental variables from the workspace except for the subset of variables that are required later on in the script. For example...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    a &amp;lt;- c(1, 2, 3)&lt;br /&gt;
    b &amp;lt;- c(2, 3, 4)&lt;br /&gt;
    c &amp;lt;- c(3, 4, 5)&lt;br /&gt;
    d &amp;lt;- c(4, 5, 6)&lt;br /&gt;
    e &amp;lt;- c(5, 6, 7)&lt;br /&gt;
    f &amp;lt;- c(6, 7, 8)&lt;br /&gt;
    g &amp;lt;- cbind(a,b)&lt;br /&gt;
    h &amp;lt;- cbind(c,d)&lt;br /&gt;
    i &amp;lt;- cbind(e,f)&lt;br /&gt;
    j &amp;lt;- cbind(g,h,i)&lt;br /&gt;
    k &amp;lt;- rbind(g,h,i)&lt;br /&gt;
    &lt;br /&gt;
    rx(c(&amp;quot;j&amp;quot;,&amp;quot;k&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
this will clear&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[category:r]]&lt;br /&gt;
[[category:rstudio]]&lt;br /&gt;
[[category:rlang]]&lt;/div&gt;</summary>
		<author><name>Bradley Monk</name></author>
	</entry>
</feed>