Skip to content

Commit

Permalink
typos + sessionInfo()
Browse files Browse the repository at this point in the history
  • Loading branch information
yjunechoe committed Mar 5, 2024
1 parent 6292489 commit 6f9566f
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 22 deletions.
11 changes: 9 additions & 2 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 @@ -276,7 +276,7 @@ str(sum)

The context for my absurd rant above is that [I was just complaining](https://fosstodon.org/@yjunechoe/112039945400602627) about how I think `args()` is a rather poorly designed function.

Let's try to redesign args. I'll do three takes:
Let's try to redesign `args()`. I'll do three takes:

### Take 1) Display is the side-effect; output is trivial

Expand Down Expand Up @@ -325,7 +325,7 @@ args2(rnorm)(5)
```


### Take 1) Display is the side-effect; output is meaningful
### Take 2) Display is the side-effect; output is meaningful

One thing I neglected to mention in this blog post is that there are other ways to extract a function's arguments. One of them is `formals()`:^[But note that it has a [special behavior](https://adv-r.hadley.nz/functions.html?q=formals#primitive-functions) of returning `NULL` for primitive functions (written in C) that clearly have user-facing arguments on the R side. See also `formalArgs()`, for a shortcut to `names(formals())`]

Expand Down Expand Up @@ -376,3 +376,10 @@ typeof( args4(rnorm) )
```

Like, come on!

## sessionInfo()

```{r}
sessionInfo()
```

52 changes: 46 additions & 6 deletions _posts/2024-03-04-args-args-args-args/args-args-args-args.html
Original file line number Diff line number Diff line change
Expand Up @@ -1570,9 +1570,10 @@ <h3>Contents</h3>
<li><a href="#coda-serious-redesigning-args" id="toc-coda-serious-redesigning-args">Coda (serious): redesigning <code>args()</code></a>
<ul>
<li><a href="#take-1-display-is-the-side-effect-output-is-trivial" id="toc-take-1-display-is-the-side-effect-output-is-trivial">Take 1) Display is the side-effect; output is trivial</a></li>
<li><a href="#take-1-display-is-the-side-effect-output-is-meaningful" id="toc-take-1-display-is-the-side-effect-output-is-meaningful">Take 1) Display is the side-effect; output is meaningful</a></li>
<li><a href="#take-2-display-is-the-side-effect-output-is-meaningful" id="toc-take-2-display-is-the-side-effect-output-is-meaningful">Take 2) Display is the side-effect; output is meaningful</a></li>
<li><a href="#take-3-just-remove-the-null" id="toc-take-3-just-remove-the-null">Take 3) Just remove the <code>NULL</code></a></li>
</ul></li>
<li><a href="#sessioninfo" id="toc-sessioninfo">sessionInfo()</a></li>
</ul>
</nav>
</div>
Expand All @@ -1592,7 +1593,7 @@ <h2 id="args"><code>args()</code></h2>
</div>
<pre><code> function (name)
.Internal(args(name))
&lt;bytecode: 0x0000020d66d37fb0&gt;
&lt;bytecode: 0x0000024f98dbd180&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 @@ -1890,7 +1891,7 @@ <h2 id="tldr-str">TL;DR: <code>str()</code></h2>
<p><code>args()</code> is hereafter banned from my blog.</p>
<h2 id="coda-serious-redesigning-args">Coda (serious): redesigning <code>args()</code></h2>
<p>The context for my absurd rant above is that <a href="https://fosstodon.org/@yjunechoe/112039945400602627">I was just complaining</a> about how I think <code>args()</code> is a rather poorly designed function.</p>
<p>Let’s try to redesign args. I’ll do three takes:</p>
<p>Let’s try to redesign <code>args()</code>. I’ll do three takes:</p>
<h3 id="take-1-display-is-the-side-effect-output-is-trivial">Take 1) Display is the side-effect; output is trivial</h3>
<p>If the whole point of <code>args()</code> is to <strong>display</strong> a function’s arguments for inspection in interactive usage, then that can simply be done as a side-effect.</p>
<p>As I said above, <code>str()</code> surprisingly has this more sensible behavior out of the box. So let’s write our first redesign of <code>args()</code> which just calls <code>str()</code>:</p>
Expand Down Expand Up @@ -1948,9 +1949,9 @@ <h3 id="take-1-display-is-the-side-effect-output-is-trivial">Take 1) Display is
<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'>args2</span><span class='op'>(</span><span class='va'>rnorm</span><span class='op'>)</span><span class='op'>(</span><span class='fl'>5</span><span class='op'>)</span></span></code></pre>
</div>
<pre><code> function (..., na.rm = FALSE)</code></pre>
<pre><code> [1] -0.1377015 -1.1093728 -0.4732521 1.2939402 -1.9288874</code></pre>
<pre><code> [1] -0.5494891 1.2861975 -1.2755454 1.0817387 -0.7248563</code></pre>
</div>
<h3 id="take-1-display-is-the-side-effect-output-is-meaningful">Take 1) Display is the side-effect; output is meaningful</h3>
<h3 id="take-2-display-is-the-side-effect-output-is-meaningful">Take 2) Display is the side-effect; output is meaningful</h3>
<p>One thing I neglected to mention in this blog post is that there are other ways to extract a function’s arguments. One of them is <code>formals()</code>:<a href="#fn6" class="footnote-ref" id="fnref6" role="doc-noteref"><sup>6</sup></a></p>
<div class="layout-chunk" data-layout="l-body">
<div class="sourceCode">
Expand Down Expand Up @@ -2031,7 +2032,46 @@ <h3 id="take-3-just-remove-the-null">Take 3) Just remove the <code>NULL</code></
<pre><code> [1] &quot;closure&quot;</code></pre>
</div>
<p>Like, come on!</p>
<div class="sourceCode" id="cb45"><pre class="sourceCode r distill-force-highlighting-css"><code class="sourceCode r"></code></pre></div>
<h2 id="sessioninfo">sessionInfo()</h2>
<div class="layout-chunk" data-layout="l-body">
<div class="sourceCode">
<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/utils/sessionInfo.html'>sessionInfo</a></span><span class='op'>(</span><span class='op'>)</span></span></code></pre>
</div>
<pre><code> R version 4.3.3 (2024-02-29 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)

Matrix products: default


locale:
[1] LC_COLLATE=English_United States.utf8
[2] LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] magrittr_2.0.3

loaded via a namespace (and not attached):
[1] crayon_1.5.2 vctrs_0.6.5 cli_3.6.1 knitr_1.45
[5] rlang_1.1.2 xfun_0.41 purrr_1.0.2 styler_1.10.2
[9] jsonlite_1.8.8 htmltools_0.5.7 sass_0.4.7 fansi_1.0.5
[13] rmarkdown_2.25 R.cache_0.16.0 evaluate_0.23 jquerylib_0.1.4
[17] distill_1.6 fastmap_1.1.1 yaml_2.3.7 lifecycle_1.0.4
[21] memoise_2.0.1 compiler_4.3.3 prettycode_1.1.0 downlit_0.4.3
[25] rstudioapi_0.15.0 R.oo_1.25.0 R.utils_2.12.3 digest_0.6.33
[29] R6_2.5.1 R.methodsS3_1.8.2 bslib_0.6.1 tools_4.3.3
[33] withr_3.0.0 cachem_1.0.8</code></pre>
</div>
<div class="sourceCode" id="cb46"><pre class="sourceCode r distill-force-highlighting-css"><code class="sourceCode r"></code></pre></div>
<section id="footnotes" class="footnotes footnotes-end-of-document" role="doc-endnotes">
<hr />
<ol>
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
46 changes: 42 additions & 4 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: 0x0000020d66d37fb0&amp;gt;
&amp;lt;bytecode: 0x0000024f98dbd180&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 @@ -284,7 +284,7 @@ class="footnote-ref" id="fnref2"&gt;&lt;sup&gt;2&lt;/sup&gt;&lt;/a&gt;&lt;/p&gt;
href="https://fosstodon.org/@yjunechoe/112039945400602627"&gt;I was just
complaining&lt;/a&gt; about how I think &lt;code&gt;args()&lt;/code&gt; is a rather poorly
designed function.&lt;/p&gt;
&lt;p&gt;Let’s try to redesign args. I’ll do three takes:&lt;/p&gt;
&lt;p&gt;Let’s try to redesign &lt;code&gt;args()&lt;/code&gt;. I’ll do three takes:&lt;/p&gt;
&lt;h3 id="take-1-display-is-the-side-effect-output-is-trivial"&gt;Take 1)
Display is the side-effect; output is trivial&lt;/h3&gt;
&lt;p&gt;If the whole point of &lt;code&gt;args()&lt;/code&gt; is to
Expand Down Expand Up @@ -337,8 +337,8 @@ side-effect.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; function (..., na.rm = FALSE)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class="r"&gt;&lt;code&gt;args2(rnorm)(5)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt; function (..., na.rm = FALSE)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt; [1] 1.6536876 1.4528063 -0.3030989 -0.2270826 0.6305848&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id="take-1-display-is-the-side-effect-output-is-meaningful"&gt;Take 1)
&lt;pre&gt;&lt;code&gt; [1] 0.9164464 1.5802621 -1.3677842 0.1642751 -0.5970638&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id="take-2-display-is-the-side-effect-output-is-meaningful"&gt;Take 2)
Display is the side-effect; output is meaningful&lt;/h3&gt;
&lt;p&gt;One thing I neglected to mention in this blog post is that there are
other ways to extract a function’s arguments. One of them is
Expand Down Expand Up @@ -408,6 +408,44 @@ args4(sum)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class="r"&gt;&lt;code&gt;typeof( args4(rnorm) )&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt; [1] &amp;quot;closure&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Like, come on!&lt;/p&gt;
&lt;h2 id="sessioninfo"&gt;sessionInfo()&lt;/h2&gt;
&lt;pre class="r"&gt;&lt;code&gt;sessionInfo()&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt; R version 4.3.3 (2024-02-29 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)

Matrix products: default


locale:
[1] LC_COLLATE=English_United States.utf8
[2] LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] magrittr_2.0.3

loaded via a namespace (and not attached):
[1] jsonlite_1.8.8 compiler_4.3.3 crayon_1.5.2 xml2_1.3.6
[5] jquerylib_0.1.4 png_0.1-8 yaml_2.3.7 fastmap_1.1.1
[9] mime_0.12 R6_2.5.1 generics_0.1.3 knitr_1.45
[13] bookdown_0.37 distill_1.6 rprojroot_2.0.4 openssl_2.1.1
[17] lubridate_1.9.3 R.cache_0.16.0 bslib_0.6.1 R.utils_2.12.3
[21] rlang_1.1.2 cachem_1.0.8 prettycode_1.1.0 xfun_0.41
[25] sass_0.4.7 timechange_0.2.0 memoise_2.0.1 cli_3.6.1
[29] withr_3.0.0 digest_0.6.33 rstudioapi_0.15.0 fontawesome_0.5.2
[33] askpass_1.2.0 lifecycle_1.0.4 R.methodsS3_1.8.2 R.oo_1.25.0
[37] vctrs_0.6.5 downlit_0.4.3 evaluate_0.23 styler_1.10.2
[41] fansi_1.0.5 rmarkdown_2.25 purrr_1.0.2 tools_4.3.3
[45] htmltools_0.5.7&lt;/code&gt;&lt;/pre&gt;
&lt;pre class="r distill-force-highlighting-css"&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div class="footnotes footnotes-end-of-document"&gt;
&lt;hr /&gt;
Expand Down
52 changes: 46 additions & 6 deletions docs/posts/2024-03-04-args-args-args-args/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2704,9 +2704,10 @@ <h3>Contents</h3>
<li><a href="#coda-serious-redesigning-args" id="toc-coda-serious-redesigning-args">Coda (serious): redesigning <code>args()</code></a>
<ul>
<li><a href="#take-1-display-is-the-side-effect-output-is-trivial" id="toc-take-1-display-is-the-side-effect-output-is-trivial">Take 1) Display is the side-effect; output is trivial</a></li>
<li><a href="#take-1-display-is-the-side-effect-output-is-meaningful" id="toc-take-1-display-is-the-side-effect-output-is-meaningful">Take 1) Display is the side-effect; output is meaningful</a></li>
<li><a href="#take-2-display-is-the-side-effect-output-is-meaningful" id="toc-take-2-display-is-the-side-effect-output-is-meaningful">Take 2) Display is the side-effect; output is meaningful</a></li>
<li><a href="#take-3-just-remove-the-null" id="toc-take-3-just-remove-the-null">Take 3) Just remove the <code>NULL</code></a></li>
</ul></li>
<li><a href="#sessioninfo" id="toc-sessioninfo">sessionInfo()</a></li>
</ul>
</nav>
</div>
Expand All @@ -2726,7 +2727,7 @@ <h2 id="args"><code>args()</code></h2>
</div>
<pre><code> function (name)
.Internal(args(name))
&lt;bytecode: 0x0000020d66d37fb0&gt;
&lt;bytecode: 0x0000024f98dbd180&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 @@ -3024,7 +3025,7 @@ <h2 id="tldr-str">TL;DR: <code>str()</code></h2>
<p><code>args()</code> is hereafter banned from my blog.</p>
<h2 id="coda-serious-redesigning-args">Coda (serious): redesigning <code>args()</code></h2>
<p>The context for my absurd rant above is that <a href="https://fosstodon.org/@yjunechoe/112039945400602627">I was just complaining</a> about how I think <code>args()</code> is a rather poorly designed function.</p>
<p>Let’s try to redesign args. I’ll do three takes:</p>
<p>Let’s try to redesign <code>args()</code>. I’ll do three takes:</p>
<h3 id="take-1-display-is-the-side-effect-output-is-trivial">Take 1) Display is the side-effect; output is trivial</h3>
<p>If the whole point of <code>args()</code> is to <strong>display</strong> a function’s arguments for inspection in interactive usage, then that can simply be done as a side-effect.</p>
<p>As I said above, <code>str()</code> surprisingly has this more sensible behavior out of the box. So let’s write our first redesign of <code>args()</code> which just calls <code>str()</code>:</p>
Expand Down Expand Up @@ -3082,9 +3083,9 @@ <h3 id="take-1-display-is-the-side-effect-output-is-trivial">Take 1) Display is
<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'>args2</span><span class='op'>(</span><span class='va'>rnorm</span><span class='op'>)</span><span class='op'>(</span><span class='fl'>5</span><span class='op'>)</span></span></code></pre>
</div>
<pre><code> function (..., na.rm = FALSE)</code></pre>
<pre><code> [1] -0.1377015 -1.1093728 -0.4732521 1.2939402 -1.9288874</code></pre>
<pre><code> [1] -0.5494891 1.2861975 -1.2755454 1.0817387 -0.7248563</code></pre>
</div>
<h3 id="take-1-display-is-the-side-effect-output-is-meaningful">Take 1) Display is the side-effect; output is meaningful</h3>
<h3 id="take-2-display-is-the-side-effect-output-is-meaningful">Take 2) Display is the side-effect; output is meaningful</h3>
<p>One thing I neglected to mention in this blog post is that there are other ways to extract a function’s arguments. One of them is <code>formals()</code>:<a href="#fn6" class="footnote-ref" id="fnref6" role="doc-noteref"><sup>6</sup></a></p>
<div class="layout-chunk" data-layout="l-body">
<div class="sourceCode">
Expand Down Expand Up @@ -3165,7 +3166,46 @@ <h3 id="take-3-just-remove-the-null">Take 3) Just remove the <code>NULL</code></
<pre><code> [1] &quot;closure&quot;</code></pre>
</div>
<p>Like, come on!</p>
<div class="sourceCode" id="cb45"><pre class="sourceCode r distill-force-highlighting-css"><code class="sourceCode r"></code></pre></div>
<h2 id="sessioninfo">sessionInfo()</h2>
<div class="layout-chunk" data-layout="l-body">
<div class="sourceCode">
<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/utils/sessionInfo.html'>sessionInfo</a></span><span class='op'>(</span><span class='op'>)</span></span></code></pre>
</div>
<pre><code> R version 4.3.3 (2024-02-29 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)

Matrix products: default


locale:
[1] LC_COLLATE=English_United States.utf8
[2] LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] magrittr_2.0.3

loaded via a namespace (and not attached):
[1] crayon_1.5.2 vctrs_0.6.5 cli_3.6.1 knitr_1.45
[5] rlang_1.1.2 xfun_0.41 purrr_1.0.2 styler_1.10.2
[9] jsonlite_1.8.8 htmltools_0.5.7 sass_0.4.7 fansi_1.0.5
[13] rmarkdown_2.25 R.cache_0.16.0 evaluate_0.23 jquerylib_0.1.4
[17] distill_1.6 fastmap_1.1.1 yaml_2.3.7 lifecycle_1.0.4
[21] memoise_2.0.1 compiler_4.3.3 prettycode_1.1.0 downlit_0.4.3
[25] rstudioapi_0.15.0 R.oo_1.25.0 R.utils_2.12.3 digest_0.6.33
[29] R6_2.5.1 R.methodsS3_1.8.2 bslib_0.6.1 tools_4.3.3
[33] withr_3.0.0 cachem_1.0.8</code></pre>
</div>
<div class="sourceCode" id="cb46"><pre class="sourceCode r distill-force-highlighting-css"><code class="sourceCode r"></code></pre></div>
<section id="footnotes" class="footnotes footnotes-end-of-document" role="doc-endnotes">
<hr />
<ol>
Expand Down
Loading

0 comments on commit 6f9566f

Please sign in to comment.