File: progressr-25-replace-cli-with-progressr.html

package info (click to toggle)
r-cran-progressr 0.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,184 kB
  • sloc: sh: 13; makefile: 7
file content (108 lines) | stat: -rw-r--r-- 3,366 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>progressr: Replace 'cli' Progress Bars with 'progressr'</title>
<style>
body {
  font-family: sans-serif;
  line-height: 1.6;
  padding-left: 3ex;
  padding-right: 3ex;
  background-color: white;
  color: black;
}

a {
  color: #4183C4;
  text-decoration: none;
}

h1, h2, h3 {
  margin: 2ex 0 1ex;
  padding: 0;
  font-weight: bold;
  -webkit-font-smoothing: antialiased;
  cursor: text;
  position: relative;
}

h2 {
  border-bottom: 1px solid #cccccc;
}

code {
  margin: 0 2px;
  padding: 0 5px;
  white-space: nowrap;
  border: 1px solid #eaeaea;
  background-color: #f8f8f8;
  border-radius: 3px;
}

pre code {
  margin: 0;
  padding: 0;
  white-space: pre;
  border: none;
  background: transparent;
}

pre {
  background-color: #f8f8f8;
  border: 1px solid #cccccc;
  line-height: 2.5x;
  overflow: auto;
  padding: 0.6ex 1ex;
  border-radius: 3px;
}

pre code {
  background-color: transparent;
  border: none;
}
</style>
</head>
<body>
<h1>progressr: Replace 'cli' Progress Bars with 'progressr'</h1>
<!--
%\VignetteIndexEntry{progressr: Replace 'cli' Progress Bars with 'progressr'}
%\VignetteAuthor{Henrik Bengtsson}
%\VignetteKeyword{R}
%\VignetteKeyword{package}
%\VignetteKeyword{cli}
%\VignetteKeyword{purrr}
%\VignetteEngine{progressr::selfonly}
-->
<p>The <strong>cli</strong> package is used for progress reporting by several
packages, notably tidyverse packages. For instance, in <strong>purrr</strong>, you
can do:</p>
<pre><code class="language-r">y &lt;- purrr::map(1:100, \(x) Sys.sleep(0.1), .progress = TRUE)
</code></pre>
<p>to report on progress via the <strong>cli</strong> package as <code>map()</code> is iterating
over the elements.  Now, instead of using the default, built-in
<strong>cli</strong> progress bar, we can customize <strong>cli</strong> to report on progress
via <strong><a href="https://progressr.futureverse.org">progressr</a></strong> instead.  To do this, set R option
<code>cli.progress_handlers</code> as:</p>
<pre><code class="language-r">options(cli.progress_handlers = &quot;progressr&quot;)
</code></pre>
<p>With this option set, <strong>cli</strong> will now report on progress according to
your <code>progressr::handlers()</code> settings.  For example, with:</p>
<pre><code class="language-r">progressr::handlers(c(&quot;beepr&quot;, &quot;rstudio&quot;))
</code></pre>
<p>will report on progress using <strong>beepr</strong> and the RStudio Console
progress panel.</p>
<p>To make <strong>cli</strong> report via <strong>progressr</strong> in all your R session, set
the above R option in your <code>~/.Rprofile</code> startup file, e.g.</p>
<pre><code class="language-r">if (requireNamespace(&quot;progressr&quot;, quietly = TRUE)) {
  options(cli.progress_handlers = &quot;progressr&quot;)
}
</code></pre>
<p><em>Note:</em> A <strong>cli</strong> progress bar can have a &quot;name&quot;, which can be
specfied in <strong>purrr</strong> function via argument <code>.progress</code>,
e.g. <code>.progress = &quot;processing&quot;</code>.  This name is then displayed in front
of the progress bar.  However, because the <strong>progressr</strong> framework
does not have a concept of progress &quot;name&quot;, they are silently ignored
when using <code>options(cli.progress_handlers = &quot;progressr&quot;)</code>.</p>
</body>
</html>