Skip to content

Commit

Permalink
Deploying to gh-pages from @ d448b77 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Jan 5, 2024
1 parent 2fd32fe commit 4d00ee3
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 112 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 @@ -210,7 +210,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: 0x564b5f8c2880>
#> <bytecode: 0x562e2fa72700>
#> <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-January-04_07-13-59_swim_clean.csv"
#> [1] "2024-January-05_02-18-14_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-January-04_07-13-59"
#> [1] "2024-January-05_02-18-14"
----

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 @@ -545,18 +545,18 @@ format(Sys.time(), "%Y-%B-%d_%H-%M-%S")
----

....
#> [1] "2024-janeiro-04_04-14-00"
#> [1] "2024-janeiro-04_23-18-14"
....

After:

[source,r,cell-code]
----
outfile_path("INFILE.csv")
#> [1] "2024-January-04_07-13-59_INFILE_clean.csv"
#> [1] "2024-January-05_02-18-14_INFILE_clean.csv"
format(Sys.time(), "%Y-%B-%d_%H-%M-%S")
#> [1] "2024-January-04_07-14-00"
#> [1] "2024-January-05_02-18-14"
----

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-01-04
#> date 2024-01-05
#> pandoc 2.9.2.1 @ /usr/bin/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────
Expand Down
2 changes: 1 addition & 1 deletion book-asciidoc/structure.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ In both cases we see two active libraries, consulted in this order:
. A user library
. A system-level or global library

This setup is typical on Windows, but is something you usually need to opt into on macOS and Linuxfootnote:[For more details, see the https://whattheyforgot.org/maintaining-r.html#how-to-transfer-your-library-when-updating-r[Maintaining R section] in _What They Forgot To Teach You About R_, https://rstudio.github.io/r-manuals/r-admin/Add-on-packages.html#managing-libraries[Managing Libraries] in _R Installation and Administration_ and the R help files for `+?Startup+` and `+?.libPaths+`.]. With this setup, add-on packages installed from CRAN (or elsewhere) or under local development are kept in the user library. Above, the macOS system is used as a primary development machine and has many packages here (~1000), whereas the Windows system is only used occasionally and is much more spartan. The core set of base and recommended packages that ship with R live in the system-level library and are the same on all operating systems. This separation appeals to many developers and makes it easy to, for example, clean out your add-on packages without disturbing your base R installation.
This setup is typical on Windows, but is something you usually need to opt into on macOS and Linuxfootnote:[For more details, see the https://rstats.wtf/maintaining-r#how-to-transfer-your-library-when-updating-r[Maintaining R section] in _What They Forgot To Teach You About R_, https://rstudio.github.io/r-manuals/r-admin/Add-on-packages.html#managing-libraries[Managing Libraries] in _R Installation and Administration_ and the R help files for `+?Startup+` and `+?.libPaths+`.]. With this setup, add-on packages installed from CRAN (or elsewhere) or under local development are kept in the user library. Above, the macOS system is used as a primary development machine and has many packages here (~1000), whereas the Windows system is only used occasionally and is much more spartan. The core set of base and recommended packages that ship with R live in the system-level library and are the same on all operating systems. This separation appeals to many developers and makes it easy to, for example, clean out your add-on packages without disturbing your base R installation.

If you’re on macOS or Linux and only see one library, there is no urgent need to change anything. But next time you upgrade R, consider creating a user-level library. By default, R looks for a user library found at the path stored in the environment variable `+R_LIBS_USER+`, which itself defaults to `+~/Library/R/m/x.y/library,+` on macOS, and `+~/R/m-library/x.y+` on Linux (where `+m+` is a concise description of your CPU architecture, and `+x.y+` is the R version). You can see this path with `+Sys.getenv("R_LIBS_USER")+`. These directories do not exist by default, and the use of them must be enabled by creating the directory. When you install a new version of R, and prior to installing any add-on packages, use `+dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE)+` to create a user library in the default location. Now you will have the library setup seen above. Alternatively, you could set up a user library elsewhere and tell R about that by setting the `+R_LIBS_USER+` environment variable in `+.Renviron+`. The simplest way to edit your `+.Renviron+` file is with `+usethis::edit_r_environ()+`, which will create the file if it doesn’t exist, and open it for editing.

Expand Down
8 changes: 4 additions & 4 deletions book-asciidoc/website.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ usethis::use_pkgdown()
----

....
#> ✔ Setting active project to '/tmp/RtmpTERP8A/mypackage'
#> ✔ Setting active project to '/tmp/RtmpWwu8pz/mypackage'
#> ✔ Adding '^_pkgdown\\.yml$', '^docs$', '^pkgdown$' to '.Rbuildignore'
#> ✔ Adding 'docs' to '.gitignore'
#> ✔ Writing '_pkgdown.yml'
Expand All @@ -53,11 +53,11 @@ pkgdown::build_site()
----

....
#> ✔ Setting active project to '/tmp/RtmpTERP8A/mypackage'
#> ✔ Setting active project to '/tmp/RtmpWwu8pz/mypackage'
#> -- Installing package into temporary library -----------------------
#> == Building pkgdown site =======================================================
#> Reading from: '/tmp/RtmpTERP8A/mypackage'
#> Writing to: '/tmp/RtmpTERP8A/mypackage/docs'
#> Reading from: '/tmp/RtmpWwu8pz/mypackage'
#> Writing to: '/tmp/RtmpWwu8pz/mypackage/docs'
#> -- Initialising site -----------------------------------------------------------
#> Copying '../../../home/runner/work/_temp/Library/pkgdown/BS5/assets/link.svg' to 'link.svg'
#> Copying '../../../home/runner/work/_temp/Library/pkgdown/BS5/assets/pkgdown.js' to 'pkgdown.js'
Expand Down
22 changes: 11 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/RtmpdBNMfa/regexcite/'
#> ✔ Setting active project to '/tmp/RtmpdBNMfa/regexcite'
#> ✔ Creating '/tmp/RtmpZGyvU9/regexcite/'
#> ✔ Setting active project to '/tmp/RtmpZGyvU9/regexcite'
#> ✔ Creating 'R/'
#> ✔ Writing 'DESCRIPTION'
#> Package: regexcite
Expand Down Expand Up @@ -162,7 +162,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
|1b89a7fb71… |jennybc [email protected] |Initial commit
|5e4adcf60e… |jennybc [email protected] |Initial commit
|===

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

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

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

....
── R CMD build ─────────────────────────────────────────────────────
* checking for file ‘/tmp/RtmpdBNMfa/regexcite/DESCRIPTION’ ... OK
* checking for file ‘/tmp/RtmpZGyvU9/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.3.2/lib/R/bin/R CMD INSTALL \
/tmp/RtmpdBNMfa/regexcite_0.0.0.9000.tar.gz --install-tests
/tmp/RtmpZGyvU9/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 @@ -896,7 +896,7 @@ The very best way to render `+README.Rmd+` is with `+build_readme()+`, because i
----
build_readme()
#> ℹ Installing regexcite in temporary library
#> ℹ Building '/tmp/RtmpdBNMfa/regexcite/README.Rmd'
#> ℹ Building '/tmp/RtmpZGyvU9/regexcite/README.Rmd'
----

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

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

....
── R CMD build ─────────────────────────────────────────────────────
* checking for file ‘/tmp/RtmpdBNMfa/regexcite/DESCRIPTION’ ... OK
* checking for file ‘/tmp/RtmpZGyvU9/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.3.2/lib/R/bin/R CMD INSTALL \
/tmp/RtmpdBNMfa/regexcite_0.0.0.9000.tar.gz --install-tests
/tmp/RtmpZGyvU9/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 @@ -595,7 +595,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: 0x556c7ada3bb8&gt;</span></span>
<span><span class="co">#&gt; &lt;bytecode: 0x557db0b71410&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 @@ -474,7 +474,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-January-04_07-13-56_swim_clean.csv"</span></span>
<span><span class="co">#&gt; [1] "2024-January-05_02-18-10_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 @@ -820,7 +820,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-January-04_07-13-56"</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-January-05_02-18-11"</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">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 @@ -892,15 +892,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-janeiro-04_04-13-56"</code></pre>
<pre><code>#&gt; [1] "2024-janeiro-04_23-18-11"</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-January-04_07-13-56_INFILE_clean.csv"</span></span>
<span><span class="co">#&gt; [1] "2024-January-05_02-18-11_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-January-04_07-13-56"</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-January-05_02-18-11"</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 @@ -515,7 +515,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-01-04</span></span>
<span><span class="co">#&gt; date 2024-01-05</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 4d00ee3

Please sign in to comment.