diff --git a/_posts/2024-03-04-args-args-args-args/args-args-args-args.Rmd b/_posts/2024-03-04-args-args-args-args/args-args-args-args.Rmd index dd94532..57b582c 100644 --- a/_posts/2024-03-04-args-args-args-args/args-args-args-args.Rmd +++ b/_posts/2024-03-04-args-args-args-args/args-args-args-args.Rmd @@ -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 @@ -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())`] @@ -376,3 +376,10 @@ typeof( args4(rnorm) ) ``` Like, come on! + +## sessionInfo() + +```{r} +sessionInfo() +``` + diff --git a/_posts/2024-03-04-args-args-args-args/args-args-args-args.html b/_posts/2024-03-04-args-args-args-args/args-args-args-args.html index b3af243..dfbd436 100644 --- a/_posts/2024-03-04-args-args-args-args/args-args-args-args.html +++ b/_posts/2024-03-04-args-args-args-args/args-args-args-args.html @@ -1570,9 +1570,10 @@
args()
args()
function (name)
.Internal(args(name))
- <bytecode: 0x0000020d66d37fb0>
+ <bytecode: 0x0000024f98dbd180>
<environment: namespace:base>
But wouldn’t it be fun if I used args()
itself to get this information?
str()
args()
is hereafter banned from my blog.
args()
The context for my absurd rant above is that I was just complaining 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:
If the whole point of args()
is to display a function’s arguments for inspection in interactive usage, then that can simply be done as a side-effect.
As I said above, str()
surprisingly has this more sensible behavior out of the box. So let’s write our first redesign of args()
which just calls str()
:
args2(rnorm)(5)
function (..., na.rm = FALSE)
- [1] -0.1377015 -1.1093728 -0.4732521 1.2939402 -1.9288874
+ [1] -0.5494891 1.2861975 -1.2755454 1.0817387 -0.7248563
-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()
:6
NULL
[1] "closure"
Like, come on!
-
sessionInfo()
+ 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
+
args()
args()
function (name)
.Internal(args(name))
- <bytecode: 0x0000020d66d37fb0>
+ <bytecode: 0x0000024f98dbd180>
<environment: namespace:base>
But wouldn’t it be fun if I used args()
itself to get this information?
str()
args()
is hereafter banned from my blog.
args()
The context for my absurd rant above is that I was just complaining 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:
If the whole point of args()
is to display a function’s arguments for inspection in interactive usage, then that can simply be done as a side-effect.
As I said above, str()
surprisingly has this more sensible behavior out of the box. So let’s write our first redesign of args()
which just calls str()
:
args2(rnorm)(5)
function (..., na.rm = FALSE)
- [1] -0.1377015 -1.1093728 -0.4732521 1.2939402 -1.9288874
+ [1] -0.5494891 1.2861975 -1.2755454 1.0817387 -0.7248563
-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()
:6
NULL
[1] "closure"
Like, come on!
-
sessionInfo()
+ 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
+