Skip to content

Commit

Permalink
ij for matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
yjunechoe committed Mar 5, 2024
1 parent 3550992 commit ff39529
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions _posts/2024-03-04-args-args-args-args/args-args-args-args.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ ARGS(10) %>%

Wanna see even more unhinged?

Let's try to produce a "matrix" of `args()`. You get a choice of `n` lines, and `m` `args()` around `args` each time - all to produce a `NULL`.
Let's try to produce a "matrix" of `args()`. You get a choice of `i` "rows" of piped lines, and `j` "columns" of `args()`-around-`args` each time - all to produce a `NULL`.

Ready?

```{r}
ARGS2 <- function(n, m) {
ARGS2 <- function(i, j) {
Reduce(
f = \(x,y) bquote(.(x) %>% (.(y))),
x = rep(list(Reduce(\(x,y) call("args", x), seq_len(m), quote(args))), n)
x = rep(list(Reduce(\(x,y) call("args", x), seq_len(j), quote(args))), i)
)
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,7 @@ <h2 id="args"><code>args()</code></h2>
</div>
<pre><code> function (name)
.Internal(args(name))
&lt;bytecode: 0x00000209743b31c0&gt;
&lt;bytecode: 0x000001350ee67300&gt;
&lt;environment: namespace:base&gt;</code></pre>
</div>
<p>But wouldn’t it be fun if I used <code>args()</code> itself to get this information?</p>
Expand Down Expand Up @@ -1798,14 +1798,14 @@ <h2 id="had-enough-args-yet">Had enough <code>args()</code> yet?</h2>
args()</code></pre>
</div>
<p>Wanna see even more unhinged?</p>
<p>Let’s try to produce a “matrix” of <code>args()</code>. You get a choice of <code>n</code> lines, and <code>m</code> <code>args()</code> around <code>args</code> each time - all to produce a <code>NULL</code>.</p>
<p>Let’s try to produce a “matrix” of <code>args()</code>. You get a choice of <code>i</code> “rows” of piped lines, and <code>j</code> “columns” of <code>args()</code>-around-<code>args</code> each time - all to produce a <code>NULL</code>.</p>
<p>Ready?</p>
<div class="layout-chunk" data-layout="l-body">
<div class="sourceCode">
<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>ARGS2</span> <span class='op'>&lt;-</span> <span class='kw'>function</span><span class='op'>(</span><span class='va'>n</span>, <span class='va'>m</span><span class='op'>)</span> <span class='op'>{</span></span>
<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>ARGS2</span> <span class='op'>&lt;-</span> <span class='kw'>function</span><span class='op'>(</span><span class='va'>i</span>, <span class='va'>j</span><span class='op'>)</span> <span class='op'>{</span></span>
<span> <span class='fu'><a href='https://rdrr.io/r/base/funprog.html'>Reduce</a></span><span class='op'>(</span></span>
<span> f <span class='op'>=</span> \<span class='op'>(</span><span class='va'>x</span>,<span class='va'>y</span><span class='op'>)</span> <span class='fu'><a href='https://rdrr.io/r/base/bquote.html'>bquote</a></span><span class='op'>(</span><span class='fu'>.</span><span class='op'>(</span><span class='va'>x</span><span class='op'>)</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%&gt;%</a></span> <span class='op'>(</span><span class='fu'>.</span><span class='op'>(</span><span class='va'>y</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span>,</span>
<span> x <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/list.html'>list</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/funprog.html'>Reduce</a></span><span class='op'>(</span>\<span class='op'>(</span><span class='va'>x</span>,<span class='va'>y</span><span class='op'>)</span> <span class='fu'><a href='https://rdrr.io/r/base/call.html'>call</a></span><span class='op'>(</span><span class='st'>"args"</span>, <span class='va'>x</span><span class='op'>)</span>, <span class='fu'><a href='https://rdrr.io/r/base/seq.html'>seq_len</a></span><span class='op'>(</span><span class='va'>m</span><span class='op'>)</span>, <span class='fu'><a href='https://rdrr.io/r/base/substitute.html'>quote</a></span><span class='op'>(</span><span class='va'>args</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span>, <span class='va'>n</span><span class='op'>)</span></span>
<span> x <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/list.html'>list</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/funprog.html'>Reduce</a></span><span class='op'>(</span>\<span class='op'>(</span><span class='va'>x</span>,<span class='va'>y</span><span class='op'>)</span> <span class='fu'><a href='https://rdrr.io/r/base/call.html'>call</a></span><span class='op'>(</span><span class='st'>"args"</span>, <span class='va'>x</span><span class='op'>)</span>, <span class='fu'><a href='https://rdrr.io/r/base/seq.html'>seq_len</a></span><span class='op'>(</span><span class='va'>j</span><span class='op'>)</span>, <span class='fu'><a href='https://rdrr.io/r/base/substitute.html'>quote</a></span><span class='op'>(</span><span class='va'>args</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span>, <span class='va'>i</span><span class='op'>)</span></span>
<span> <span class='op'>)</span></span>
<span><span class='op'>}</span></span></code></pre>
</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/blog.html
Original file line number Diff line number Diff line change
Expand Up @@ -3508,7 +3508,7 @@ <h3>Categories</h3>
<a href="#">More articles &raquo;</a>
</div>
</div>
<!--/radix_placeholder_article_listing-->
<!--/radix_placeholder_article_listing-->

<div class="d-title">
<h1>Blog Posts</h1>
Expand Down
12 changes: 6 additions & 6 deletions docs/blog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ start by looking at the argument that &lt;code&gt;args()&lt;/code&gt; takes.&lt;
&lt;pre class="r"&gt;&lt;code&gt;args&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt; function (name)
.Internal(args(name))
&amp;lt;bytecode: 0x00000209743b31c0&amp;gt;
&amp;lt;bytecode: 0x000001350ee67300&amp;gt;
&amp;lt;environment: namespace:base&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But wouldn’t it be fun if I used &lt;code&gt;args()&lt;/code&gt; itself to get
this information?&lt;/p&gt;
Expand Down Expand Up @@ -216,14 +216,14 @@ ARGS &amp;lt;- function(n) {
args()&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Wanna see even more unhinged?&lt;/p&gt;
&lt;p&gt;Let’s try to produce a “matrix” of &lt;code&gt;args()&lt;/code&gt;. You get a
choice of &lt;code&gt;n&lt;/code&gt; lines, and &lt;code&gt;m&lt;/code&gt; &lt;code&gt;args()&lt;/code&gt;
around &lt;code&gt;args&lt;/code&gt; each time - all to produce a
&lt;code&gt;NULL&lt;/code&gt;.&lt;/p&gt;
choice of &lt;code&gt;i&lt;/code&gt; “rows” of piped lines, and &lt;code&gt;j&lt;/code&gt;
“columns” of &lt;code&gt;args()&lt;/code&gt;-around-&lt;code&gt;args&lt;/code&gt; each time -
all to produce a &lt;code&gt;NULL&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Ready?&lt;/p&gt;
&lt;pre class="r"&gt;&lt;code&gt;ARGS2 &amp;lt;- function(n, m) {
&lt;pre class="r"&gt;&lt;code&gt;ARGS2 &amp;lt;- function(i, j) {
Reduce(
f = \(x,y) bquote(.(x) %&amp;gt;% (.(y))),
x = rep(list(Reduce(\(x,y) call(&amp;quot;args&amp;quot;, x), seq_len(m), quote(args))), n)
x = rep(list(Reduce(\(x,y) call(&amp;quot;args&amp;quot;, x), seq_len(j), quote(args))), i)
)
}&lt;/code&gt;&lt;/pre&gt;
&lt;pre class="r"&gt;&lt;code&gt;ARGS2(5, 1) %&amp;gt;%
Expand Down
8 changes: 4 additions & 4 deletions docs/posts/2024-03-04-args-args-args-args/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2720,7 +2720,7 @@ <h2 id="args"><code>args()</code></h2>
</div>
<pre><code> function (name)
.Internal(args(name))
&lt;bytecode: 0x00000209743b31c0&gt;
&lt;bytecode: 0x000001350ee67300&gt;
&lt;environment: namespace:base&gt;</code></pre>
</div>
<p>But wouldn’t it be fun if I used <code>args()</code> itself to get this information?</p>
Expand Down Expand Up @@ -2932,14 +2932,14 @@ <h2 id="had-enough-args-yet">Had enough <code>args()</code> yet?</h2>
args()</code></pre>
</div>
<p>Wanna see even more unhinged?</p>
<p>Let’s try to produce a “matrix” of <code>args()</code>. You get a choice of <code>n</code> lines, and <code>m</code> <code>args()</code> around <code>args</code> each time - all to produce a <code>NULL</code>.</p>
<p>Let’s try to produce a “matrix” of <code>args()</code>. You get a choice of <code>i</code> “rows” of piped lines, and <code>j</code> “columns” of <code>args()</code>-around-<code>args</code> each time - all to produce a <code>NULL</code>.</p>
<p>Ready?</p>
<div class="layout-chunk" data-layout="l-body">
<div class="sourceCode">
<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>ARGS2</span> <span class='op'>&lt;-</span> <span class='kw'>function</span><span class='op'>(</span><span class='va'>n</span>, <span class='va'>m</span><span class='op'>)</span> <span class='op'>{</span></span>
<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>ARGS2</span> <span class='op'>&lt;-</span> <span class='kw'>function</span><span class='op'>(</span><span class='va'>i</span>, <span class='va'>j</span><span class='op'>)</span> <span class='op'>{</span></span>
<span> <span class='fu'><a href='https://rdrr.io/r/base/funprog.html'>Reduce</a></span><span class='op'>(</span></span>
<span> f <span class='op'>=</span> \<span class='op'>(</span><span class='va'>x</span>,<span class='va'>y</span><span class='op'>)</span> <span class='fu'><a href='https://rdrr.io/r/base/bquote.html'>bquote</a></span><span class='op'>(</span><span class='fu'>.</span><span class='op'>(</span><span class='va'>x</span><span class='op'>)</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%&gt;%</a></span> <span class='op'>(</span><span class='fu'>.</span><span class='op'>(</span><span class='va'>y</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span>,</span>
<span> x <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/list.html'>list</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/funprog.html'>Reduce</a></span><span class='op'>(</span>\<span class='op'>(</span><span class='va'>x</span>,<span class='va'>y</span><span class='op'>)</span> <span class='fu'><a href='https://rdrr.io/r/base/call.html'>call</a></span><span class='op'>(</span><span class='st'>"args"</span>, <span class='va'>x</span><span class='op'>)</span>, <span class='fu'><a href='https://rdrr.io/r/base/seq.html'>seq_len</a></span><span class='op'>(</span><span class='va'>m</span><span class='op'>)</span>, <span class='fu'><a href='https://rdrr.io/r/base/substitute.html'>quote</a></span><span class='op'>(</span><span class='va'>args</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span>, <span class='va'>n</span><span class='op'>)</span></span>
<span> x <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/list.html'>list</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/funprog.html'>Reduce</a></span><span class='op'>(</span>\<span class='op'>(</span><span class='va'>x</span>,<span class='va'>y</span><span class='op'>)</span> <span class='fu'><a href='https://rdrr.io/r/base/call.html'>call</a></span><span class='op'>(</span><span class='st'>"args"</span>, <span class='va'>x</span><span class='op'>)</span>, <span class='fu'><a href='https://rdrr.io/r/base/seq.html'>seq_len</a></span><span class='op'>(</span><span class='va'>j</span><span class='op'>)</span>, <span class='fu'><a href='https://rdrr.io/r/base/substitute.html'>quote</a></span><span class='op'>(</span><span class='va'>args</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span>, <span class='va'>i</span><span class='op'>)</span></span>
<span> <span class='op'>)</span></span>
<span><span class='op'>}</span></span></code></pre>
</div>
Expand Down
Loading

0 comments on commit ff39529

Please sign in to comment.