Skip to content

Commit

Permalink
Deploying to gh-pages from @ 216bbc7 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Oct 25, 2024
1 parent 56207b5 commit 40a26ee
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 110 deletions.
2 changes: 1 addition & 1 deletion book-asciidoc/dependencies-mindset-background.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ sd
#> function (x, na.rm = FALSE)
#> sqrt(var(if (is.vector(x) || is.factor(x)) x else as.double(x),
#> na.rm = na.rm))
#> <bytecode: 0x56493426e978>
#> <bytecode: 0x55afca5beba0>
#> <environment: namespace:stats>
----

Expand Down
10 changes: 5 additions & 5 deletions book-asciidoc/package-within.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Finally, this cleaned (cleaner?) data is written back out to a CSV file. They li
now <- Sys.time()
timestamp <- format(now, "%Y-%B-%d_%H-%M-%S")
(outfile <- paste0(timestamp, "_", sub("(.*)([.]csv$)", "\\1_clean\\2", infile)))
#> [1] "2024-October-24_07-15-28_swim_clean.csv"
#> [1] "2024-October-25_07-14-52_swim_clean.csv"
write.csv(dat, file = outfile, quote = FALSE, row.names = FALSE)
----

Expand Down Expand Up @@ -503,7 +503,7 @@ The timestamps now reflect the current time, but the group raises a new concern.
[source,r,cell-code]
----
format(Sys.time(), "%Y-%B-%d_%H-%M-%S")
#> [1] "2024-October-24_07-15-28"
#> [1] "2024-October-25_07-14-52"
----

This formats `+Sys.time()+` in such a way that it includes the month _name_ (not number) and the local timefootnote:[It would clearly be better to format according to ISO 8601, which encodes the month by number, but please humor me for the sake of making this example more obvious.].
Expand Down Expand Up @@ -549,18 +549,18 @@ format(Sys.time(), "%Y-%B-%d_%H-%M-%S")
----

....
#> [1] "2024-outubro-24_04-15-28"
#> [1] "2024-outubro-25_04-14-53"
....

After:

[source,r,cell-code]
----
outfile_path("INFILE.csv")
#> [1] "2024-October-24_07-15-28_INFILE_clean.csv"
#> [1] "2024-October-25_07-14-52_INFILE_clean.csv"
format(Sys.time(), "%Y-%B-%d_%H-%M-%S")
#> [1] "2024-October-24_07-15-28"
#> [1] "2024-October-25_07-14-53"
----

Notice that her month name switched from Portuguese to English and the time is clearly being reported in a different time zone. The calls to `+Sys.setlocale()+` and `+Sys.setenv()+` inside `+timestamp()+` have made persistent (and very surprising) changes to her R session. This sort of side effect is very undesirable and is extremely difficult to track down and debug, especially in more complicated settings.
Expand Down
2 changes: 1 addition & 1 deletion book-asciidoc/preface.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ devtools::session_info()
#> collate C.UTF-8
#> ctype C.UTF-8
#> tz UTC
#> date 2024-10-24
#> date 2024-10-25
#> pandoc 2.9.2.1 @ /usr/bin/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────
Expand Down
8 changes: 4 additions & 4 deletions book-asciidoc/website.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ usethis::use_pkgdown()
----

....
#> ✔ Setting active project to "/tmp/RtmpRZJ87K/mypackage".
#> ✔ Setting active project to "/tmp/Rtmptervux/mypackage".
#> ✔ Adding "^_pkgdown\\.yml$", "^docs$", and "^pkgdown$" to
#> '.Rbuildignore'.
#> ✔ Adding "docs" to '.gitignore'.
Expand All @@ -51,7 +51,7 @@ pkgdown::build_site()
----

....
#> ✔ Setting active project to "/tmp/RtmpRZJ87K/mypackage".
#> ✔ Setting active project to "/tmp/Rtmptervux/mypackage".
#> ── Installing package mypackage into temporary library ─────────────
#> ── Initialising site ───────────────────────────────────────────────────────────
#> Copying <pkgdown>/BS5/assets/katex-auto.js to katex-auto.js
Expand Down Expand Up @@ -84,8 +84,8 @@ pkgdown::build_site()
#> Updating deps/search-1.0.0/fuse.min.js
#> Updating deps/search-1.0.0/mark.min.js
#> ── Building pkgdown site for package mypackage ─────────────────────────────────
#> Reading from: /tmp/RtmpRZJ87K/mypackage
#> Writing to: /tmp/RtmpRZJ87K/mypackage/docs
#> Reading from: /tmp/Rtmptervux/mypackage
#> Writing to: /tmp/Rtmptervux/mypackage/docs
#> ── Sitrep ──────────────────────────────────────────────────────────────────────
#> ✖ URLs not ok.
#> In _pkgdown.yml, url is missing.
Expand Down
24 changes: 13 additions & 11 deletions book-asciidoc/whole-game.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ create_package("~/path/to/regexcite")
For the creation of this book we have to work in a temporary directory, because the book is built non-interactively in the cloud. Behind the scenes, we’re executing our own `+create_package()+` command, but don’t be surprised if our output differs a bit from yours.

....
#> ✔ Creating '/tmp/RtmpZYxZ2g/regexcite/'.
#> ✔ Setting active project to "/tmp/RtmpZYxZ2g/regexcite".
#> ✔ Creating '/tmp/RtmpyhfWhP/regexcite/'.
#> ✔ Setting active project to "/tmp/RtmpyhfWhP/regexcite".
#> ✔ Creating 'R/'.
#> ✔ Writing 'DESCRIPTION'.
#> Package: regexcite
Expand Down Expand Up @@ -159,7 +159,7 @@ Click on History (the clock icon in the Git pane) and, if you consented, you wil
[width="100%",cols="<21%,<59%,<20%",options="header",]
|===
|commit |author |message
|fd199946bd… |jennybc [email protected] |Initial commit
|45717b3674… |jennybc [email protected] |Initial commit
|===

[TIP]
Expand Down Expand Up @@ -320,7 +320,7 @@ check()

....
── R CMD check results ─────────────────── regexcite 0.0.0.9000 ────
Duration: 7.3s
Duration: 6.8s
❯ checking DESCRIPTION meta-information ... WARNING
Non-standard license specification:
Expand Down Expand Up @@ -496,7 +496,7 @@ check()

....
── R CMD check results ─────────────────── regexcite 0.0.0.9000 ────
Duration: 8.9s
Duration: 8.2s
0 errors ✔ | 0 warnings ✔ | 0 notes ✔
....
Expand All @@ -512,14 +512,14 @@ install()

....
── R CMD build ─────────────────────────────────────────────────────
* checking for file ‘/tmp/RtmpZYxZ2g/regexcite/DESCRIPTION’ ... OK
* checking for file ‘/tmp/RtmpyhfWhP/regexcite/DESCRIPTION’ ... OK
* preparing ‘regexcite’:
* checking DESCRIPTION meta-information ... OK
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building ‘regexcite_0.0.0.9000.tar.gz’
Running /opt/R/4.4.1/lib/R/bin/R CMD INSTALL \
/tmp/RtmpZYxZ2g/regexcite_0.0.0.9000.tar.gz --install-tests
/tmp/RtmpyhfWhP/regexcite_0.0.0.9000.tar.gz --install-tests
* installing to library ‘/home/runner/work/_temp/Library’
* installing *source* package ‘regexcite’ ...
** using staged installation
Expand Down Expand Up @@ -609,6 +609,8 @@ test()
#>
#> ══ Results ═════════════════════════════════════════════════════════
#> [ FAIL 0 | WARN 0 | SKIP 0 | PASS 1 ]
#>
#> 💣 Your tests are da bomb 💣
----

[TIP]
Expand Down Expand Up @@ -874,7 +876,7 @@ The very best way to render `+README.Rmd+` is with `+build_readme()+`, because i
----
build_readme()
#> ℹ Installing regexcite in temporary library
#> ℹ Building '/tmp/RtmpZYxZ2g/regexcite/README.Rmd'
#> ℹ Building '/tmp/RtmpyhfWhP/regexcite/README.Rmd'
----

You can see the rendered `+README.md+` simply by https://github.com/jennybc/regexcite#readme[visiting regexcite on GitHub].
Expand All @@ -892,7 +894,7 @@ check()

....
── R CMD check results ─────────────────── regexcite 0.0.0.9000 ────
Duration: 10.3s
Duration: 9.9s
0 errors ✔ | 0 warnings ✔ | 0 notes ✔
....
Expand All @@ -906,15 +908,15 @@ install()

....
── R CMD build ─────────────────────────────────────────────────────
* checking for file ‘/tmp/RtmpZYxZ2g/regexcite/DESCRIPTION’ ... OK
* checking for file ‘/tmp/RtmpyhfWhP/regexcite/DESCRIPTION’ ... OK
* preparing ‘regexcite’:
* checking DESCRIPTION meta-information ... OK
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
Removed empty directory ‘regexcite/tests/testthat/_snaps’
* building ‘regexcite_0.0.0.9000.tar.gz’
Running /opt/R/4.4.1/lib/R/bin/R CMD INSTALL \
/tmp/RtmpZYxZ2g/regexcite_0.0.0.9000.tar.gz --install-tests
/tmp/RtmpyhfWhP/regexcite_0.0.0.9000.tar.gz --install-tests
* installing to library ‘/home/runner/work/_temp/Library’
* installing *source* package ‘regexcite’ ...
** using staged installation
Expand Down
2 changes: 1 addition & 1 deletion dependencies-mindset-background.html
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ <h1 class="title"><span id="sec-dependencies-mindset-background" class="quarto-s
<span><span class="co">#&gt; function (x, na.rm = FALSE) </span></span>
<span><span class="co">#&gt; sqrt(var(if (is.vector(x) || is.factor(x)) x else as.double(x), </span></span>
<span><span class="co">#&gt; na.rm = na.rm))</span></span>
<span><span class="co">#&gt; &lt;bytecode: 0x55f8447cf470&gt;</span></span>
<span><span class="co">#&gt; &lt;bytecode: 0x56416d42bfe0&gt;</span></span>
<span><span class="co">#&gt; &lt;environment: namespace:stats&gt;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>It’s defined in terms of another function, <code><a href="https://rdrr.io/r/stats/cor.html">var()</a></code>, also from the stats package. So what happens if we override <code><a href="https://rdrr.io/r/stats/cor.html">var()</a></code> with our own definition? Does it break <code><a href="https://rdrr.io/r/stats/sd.html">sd()</a></code>?</p>
Expand Down
10 changes: 5 additions & 5 deletions package-within.html
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ <h1 class="title"><span id="sec-package-within" class="quarto-section-identifier
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va">now</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/Sys.time.html">Sys.time</a></span><span class="op">(</span><span class="op">)</span></span>
<span><span class="va">timestamp</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/format.html">format</a></span><span class="op">(</span><span class="va">now</span>, <span class="st">"%Y-%B-%d_%H-%M-%S"</span><span class="op">)</span></span>
<span><span class="op">(</span><span class="va">outfile</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste0</a></span><span class="op">(</span><span class="va">timestamp</span>, <span class="st">"_"</span>, <span class="fu"><a href="https://rdrr.io/r/base/grep.html">sub</a></span><span class="op">(</span><span class="st">"(.*)([.]csv$)"</span>, <span class="st">"\\1_clean\\2"</span>, <span class="va">infile</span><span class="op">)</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="co">#&gt; [1] "2024-October-24_07-15-24_swim_clean.csv"</span></span>
<span><span class="co">#&gt; [1] "2024-October-25_07-14-49_swim_clean.csv"</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/utils/write.table.html">write.csv</a></span><span class="op">(</span><span class="va">dat</span>, file <span class="op">=</span> <span class="va">outfile</span>, quote <span class="op">=</span> <span class="cn">FALSE</span>, row.names <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Here is <code>data-cleaning.R</code> in its entirety:</p>
Expand Down Expand Up @@ -828,7 +828,7 @@ <h1 class="title"><span id="sec-package-within" class="quarto-section-identifier
<p>The timestamps now reflect the current time, but the group raises a new concern. As it stands, the timestamps reflect who has done the data cleaning and which part of the world they’re in. The heart of the timestamp strategy is this format string<a href="#fn5" class="footnote-ref" id="fnref5" role="doc-noteref"><sup>5</sup></a>:</p>
<div class="cell">
<div class="sourceCode" id="cb28"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/base/format.html">format</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/Sys.time.html">Sys.time</a></span><span class="op">(</span><span class="op">)</span>, <span class="st">"%Y-%B-%d_%H-%M-%S"</span><span class="op">)</span></span>
<span><span class="co">#&gt; [1] "2024-October-24_07-15-24"</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<span><span class="co">#&gt; [1] "2024-October-25_07-14-49"</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>This formats <code><a href="https://rdrr.io/r/base/Sys.time.html">Sys.time()</a></code> in such a way that it includes the month <em>name</em> (not number) and the local time<a href="#fn6" class="footnote-ref" id="fnref6" role="doc-noteref"><sup>6</sup></a>.</p>
<p><a href="#tbl-timestamps" class="quarto-xref">Table&nbsp;<span>5.1</span></a> shows what happens when such a timestamp is produced by several hypothetical colleagues cleaning some data at exactly the same instant in time.</p>
Expand Down Expand Up @@ -904,15 +904,15 @@ <h1 class="title"><span id="sec-package-within" class="quarto-section-identifier
<div class="sourceCode" id="cb30"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/base/format.html">format</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/Sys.time.html">Sys.time</a></span><span class="op">(</span><span class="op">)</span>, <span class="st">"%Y-%B-%d_%H-%M-%S"</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell">
<pre><code>#&gt; [1] "2024-outubro-24_04-15-25"</code></pre>
<pre><code>#&gt; [1] "2024-outubro-25_04-14-49"</code></pre>
</div>
<p>After:</p>
<div class="cell">
<div class="sourceCode" id="cb32"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu">outfile_path</span><span class="op">(</span><span class="st">"INFILE.csv"</span><span class="op">)</span></span>
<span><span class="co">#&gt; [1] "2024-October-24_07-15-24_INFILE_clean.csv"</span></span>
<span><span class="co">#&gt; [1] "2024-October-25_07-14-49_INFILE_clean.csv"</span></span>
<span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/format.html">format</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/Sys.time.html">Sys.time</a></span><span class="op">(</span><span class="op">)</span>, <span class="st">"%Y-%B-%d_%H-%M-%S"</span><span class="op">)</span></span>
<span><span class="co">#&gt; [1] "2024-October-24_07-15-25"</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<span><span class="co">#&gt; [1] "2024-October-25_07-14-49"</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Notice that her month name switched from Portuguese to English and the time is clearly being reported in a different time zone. The calls to <code><a href="https://rdrr.io/r/base/locales.html">Sys.setlocale()</a></code> and <code><a href="https://rdrr.io/r/base/Sys.setenv.html">Sys.setenv()</a></code> inside <code><a href="https://rdrr.io/r/utils/savehistory.html">timestamp()</a></code> have made persistent (and very surprising) changes to her R session. This sort of side effect is very undesirable and is extremely difficult to track down and debug, especially in more complicated settings.</p>
<p>Here are better versions of <code><a href="https://rdrr.io/r/utils/savehistory.html">timestamp()</a></code>:</p>
Expand Down
2 changes: 1 addition & 1 deletion preface.html
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ <h1 class="title"><span id="sec-preface" class="quarto-section-identifier">Prefa
<span><span class="co">#&gt; collate C.UTF-8</span></span>
<span><span class="co">#&gt; ctype C.UTF-8</span></span>
<span><span class="co">#&gt; tz UTC</span></span>
<span><span class="co">#&gt; date 2024-10-24</span></span>
<span><span class="co">#&gt; date 2024-10-25</span></span>
<span><span class="co">#&gt; pandoc 2.9.2.1 @ /usr/bin/ (via rmarkdown)</span></span>
<span><span class="co">#&gt; </span></span>
<span><span class="co">#&gt; ─ Packages ───────────────────────────────────────────────────────</span></span>
Expand Down
Loading

0 comments on commit 40a26ee

Please sign in to comment.