<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>Today I Learned</title>
<link>https://o957.github.io/O957-TIL/</link>
<atom:link href="https://o957.github.io/O957-TIL/index.xml" rel="self" type="application/rss+xml"/>
<description>A collection of references and demonstrations for concepts and methods that I have come across and want to mentally retain.</description>
<generator>quarto-1.9.38</generator>
<lastBuildDate>Mon, 01 Dec 2025 00:00:00 GMT</lastBuildDate>
<item>
  <title>Switch To VSCodium From VSCode</title>
  <link>https://o957.github.io/O957-TIL/posts/ide_vs_codium.html</link>
  <description><![CDATA[ 





<p><em>Today I Learned added on 2026-06-14, learned sometime around 2025-12-01.</em></p>
<p>In reviewing which tools are comparatively better with respect to privacy on <a href="https://github.com/pluja/awesome-privacy" class="uri">https://github.com/pluja/awesome-privacy</a>, I noticed that VSCodium (<a href="https://vscodium.com/" class="uri">https://vscodium.com/</a>) was listed.</p>
<p>Curious, I went to their website and saw the following:</p>
<blockquote class="blockquote">
<p>Microsoft’s <code>vscode</code> source code is open source (MIT-licensed), but the product available for download (Visual Studio Code) is licensed under <a href="https://code.visualstudio.com/license">this not-FLOSS license</a> and contains telemetry/tracking. According to <a href="https://github.com/Microsoft/vscode/issues/60#issuecomment-161792005">this comment</a> from a Visual Studio Code maintainer:</p>
<blockquote class="blockquote">
<p>When we [Microsoft] build Visual Studio Code, we do exactly this. We clone the vscode repository, we lay down a customized product.json that has Microsoft specific functionality (telemetry, gallery, logo, etc.), and then produce a build that we release under our license.</p>
<p>When you clone and build from the vscode repo, none of these endpoints are configured in the default product.json. Therefore, you generate a “clean” build, without the Microsoft customizations, which is by default licensed under the MIT license</p>
</blockquote>
<p>The VSCodium project exists so that you don’t have to download+build from source. This project includes special build scripts that clone Microsoft’s vscode repo, run the build commands, and upload the resulting binaries for you to <a href="https://github.com/VSCodium/vscodium/releases">GitHub releases</a>. <strong>These binaries are licensed under the MIT license. Telemetry is disabled</strong></p>
</blockquote>
<p>Sold, I switched that day to VSCodium and I have not regretted my choice!</p>
<p>As for the name “Codium” and the logo (which looks like some sort of sea coral), I found Codium (<a href="https://en.wikipedia.org/wiki/Codium" class="uri">https://en.wikipedia.org/wiki/Codium</a>) on Wikipedia:</p>
<blockquote class="blockquote">
<p><strong><em>Codium</em></strong> is a <a href="https://en.wikipedia.org/wiki/Genus" title="Genus">genus</a> of <a href="https://en.wikipedia.org/wiki/Edible_seaweed" title="Edible seaweed">edible</a> <a href="https://en.wikipedia.org/wiki/Green_algae" title="Green algae">green macroalgae</a> (or <a href="https://en.wikipedia.org/wiki/Seaweed" title="Seaweed">seaweed</a>) under the order <a href="https://en.wikipedia.org/wiki/Bryopsidales" title="Bryopsidales">Bryopsidales</a>. The genus name is derived from a Greek word that pertains to the soft texture of its <a href="https://en.wikipedia.org/wiki/Thallus" title="Thallus">thallus</a>. One of the foremost experts on <em>Codium</em> taxonomy was <a href="https://en.wikipedia.org/wiki/Paul_Silva" title="Paul Silva">Paul Claude Silva</a> at the <a href="https://en.wikipedia.org/wiki/University_of_California,_Berkeley" title="University of California, Berkeley">University of California, Berkeley</a>. <a href="https://en.wikipedia.org/wiki/Codium#cite_note-:0-1">1</a> <a href="https://en.wikipedia.org/wiki/Codium#cite_note-Hoek,_Mann_and_Jahns_95-2">2</a> Silva was able to describe 36 species for the genus, and in honor of his work on <em>Codium</em>, <a href="https://en.wikipedia.org/wiki/Codium#cite_note-:0-1">1</a> the species <em>C. silvae</em> was named after him. <a href="https://en.wikipedia.org/wiki/Codium#cite_note-:1-3">3</a></p>
</blockquote>


<!-- -->


 ]]></description>
  <category>vscode</category>
  <category>vscodium</category>
  <category>IDE</category>
  <category>privacy</category>
  <guid>https://o957.github.io/O957-TIL/posts/ide_vs_codium.html</guid>
  <pubDate>Mon, 01 Dec 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Opening VS Code From The Terminal Via Code</title>
  <link>https://o957.github.io/O957-TIL/posts/ide_open_vscode_from_cmd_line.html</link>
  <description><![CDATA[ 





<p><em>Today I Learned added on 2025-11-30, learned on 2025-11-30; edited on 2026-06-14.</em></p>
<p>For my paid and unpaid programming work I’ve used <a href="https://code.visualstudio.com">VS Code</a>. The following has been routine for me for roughly 4 years: I open the target folder by pressing the <code>Open</code> button on VS Code’s platform or, if I remember to, to <code>Cmd+O</code> on my MacOS to open a folder.</p>
<p>Today, I remarked internally to myself that VS Code probably has a method to open a new window from within the Terminal. Lo and behold, it does: <code>code .</code> to open the current directory in VS Code.</p>
<p>Of note, to get the <code>code</code> command working, I performed the following actions:</p>
<ol type="1">
<li>Open VS Code.</li>
<li>Open Command Palette via <code>Cmd+Shift+P</code>.</li>
<li>Type: “shell command”</li>
<li>Select: “Shell Command: Install ‘code’ command in PATH”</li>
<li>Gave permissions to VS Code.</li>
</ol>
<p>Running <code>code --help</code> shows some other interesting options:</p>
<pre><code>code --help
Visual Studio Code 1.105.1

Usage: code [options] [paths...]

To read from stdin, append '-' (e.g. 'ps aux | grep code | code -')

Options
  -d --diff &lt;file&gt; &lt;file&gt;                    Compare two files with each other.
  -m --merge &lt;path1&gt; &lt;path2&gt; &lt;base&gt; &lt;result&gt; Perform a three-way merge by providing paths for two modified versions of a
                                             file, the common origin of both modified versions and the output file to save
                                             merge results.
  -a --add &lt;folder&gt;                          Add folder(s) to the last active window.
  --remove &lt;folder&gt;                          Remove folder(s) from the last active window.
  -g --goto &lt;file:line[:character]&gt;          Open a file at the path on the specified line and character position.
  -n --new-window                            Force to open a new window.
  -r --reuse-window                          Force to open a file or folder in an already opened window.
  -w --wait                                  Wait for the files to be closed before returning.
  --locale &lt;locale&gt;                          The locale to use (e.g. en-US or zh-TW).
  --user-data-dir &lt;dir&gt;                      Specifies the directory that user data is kept in. Can be used to open
                                             multiple distinct instances of Code.
  --profile &lt;profileName&gt;                    Opens the provided folder or workspace with the given profile and associates
                                             the profile with the workspace. If the profile does not exist, a new empty
                                             one is created.
  -h --help                                  Print usage.

Extensions Management
  --extensions-dir &lt;dir&gt;              Set the root path for extensions.
  --list-extensions                   List the installed extensions.
  --show-versions                     Show versions of installed extensions, when using --list-extensions.
  --category &lt;category&gt;               Filters installed extensions by provided category, when using --list-extensions.
  --install-extension &lt;ext-id | path&gt; Installs or updates an extension. The argument is either an extension id or a path
                                      to a VSIX. The identifier of an extension is '${publisher}.${name}'. Use '--force'
                                      argument to update to latest version. To install a specific version provide
                                      '@${version}'. For example: 'vscode.csharp@1.2.3'.
  --pre-release                       Installs the pre-release version of the extension, when using --install-extension
  --uninstall-extension &lt;ext-id&gt;      Uninstalls an extension.
  --update-extensions                 Update the installed extensions.
  --enable-proposed-api &lt;ext-id&gt;      Enables proposed API features for extensions. Can receive one or more extension IDs
                                      to enable individually.

Model Context Protocol
  --add-mcp &lt;json&gt; Adds a Model Context Protocol server definition to the user profile. Accepts JSON input in the form
                   '{"name":"server-name","command":...}'

Troubleshooting
  -v --version                            Print version.
  --verbose                               Print verbose output (implies --wait).
  --log &lt;level&gt;                           Log level to use. Default is 'info'. Allowed values are 'critical', 'error',
                                          'warn', 'info', 'debug', 'trace', 'off'. You can also configure the log level of
                                          an extension by passing extension id and log level in the following format:
                                          '${publisher}.${name}:${logLevel}'. For example: 'vscode.csharp:trace'. Can
                                          receive one or more such entries.
  -s --status                             Print process usage and diagnostics information.
  --prof-startup                          Run CPU profiler during startup.
  --disable-extensions                    Disable all installed extensions. This option is not persisted and is effective
                                          only when the command opens a new window.
  --disable-extension &lt;ext-id&gt;            Disable the provided extension. This option is not persisted and is effective
                                          only when the command opens a new window.
  --sync &lt;on | off&gt;                       Turn sync on or off.
  --inspect-extensions &lt;port&gt;             Allow debugging and profiling of extensions. Check the developer tools for the
                                          connection URI.
  --inspect-brk-extensions &lt;port&gt;         Allow debugging and profiling of extensions with the extension host being paused
                                          after start. Check the developer tools for the connection URI.
  --disable-lcd-text                      Disable LCD font rendering.
  --disable-gpu                           Disable GPU hardware acceleration.
  --disable-chromium-sandbox              Use this option only when there is requirement to launch the application as sudo
                                          user on Linux or when running as an elevated user in an applocker environment on
                                          Windows.
  --locate-shell-integration-path &lt;shell&gt; Print the path to a terminal shell integration script. Allowed values are
                                          'bash', 'pwsh', 'zsh' or 'fish'.
  --telemetry                             Shows all telemetry events which VS code collects.
  --transient                             Run with temporary data and extension directories, as if launched for the first
                                          time.

Subcommands
  chat         Pass in a prompt to run in a chat session in the current working directory.
  serve-web    Run a server that displays the editor UI in browsers.
  tunnel       Make the current machine accessible from vscode.dev or other machines through a secure tunnel.</code></pre>


<!-- -->


 ]]></description>
  <category>vscode</category>
  <category>IDE</category>
  <guid>https://o957.github.io/O957-TIL/posts/ide_open_vscode_from_cmd_line.html</guid>
  <pubDate>Sun, 30 Nov 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Handling Unbound Tidyr Variables Using Rlang Data Masking</title>
  <link>https://o957.github.io/O957-TIL/posts/r_handle_unbound_tidyr_variables.html</link>
  <description><![CDATA[ 





<p><em>Today I Learned added on 2025-11-19, learned on 2025-11-18; edited on 2026-06-14.</em></p>
<p>During some routine R-package development, I noticed a <code>NOTE</code> in a GitHub Actions (<code>Run r-lib/actions/check-r-package@v2</code>) failure, produced by the workflow <code>R-CMD-check.yaml</code>:</p>
<details>
<summary>
R CMD Check Workflow
</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Workflow derived from https://github.com/r-lib/actions/tree/v2/examples</span></span>
<span id="cb1-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help</span></span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">name</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> R-CMD-check.yaml</span></span>
<span id="cb1-4"></span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">on</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb1-6"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull_request</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb1-7"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb1-8"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">    </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">branches</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">[</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">main</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">]</span></span>
<span id="cb1-9"></span>
<span id="cb1-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">concurrency</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb1-11"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> ${{ github.workflow }}-${{ github.head_ref || github.ref }}</span></span>
<span id="cb1-12"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cancel-in-progress</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">true</span></span>
<span id="cb1-13"></span>
<span id="cb1-14"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">permissions</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> read-all</span></span>
<span id="cb1-15"></span>
<span id="cb1-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">jobs</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb1-17"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">R-CMD-check</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb1-18"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">    </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">runs-on</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> ${{ matrix.config.os }}</span></span>
<span id="cb1-19"></span>
<span id="cb1-20"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">    </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">name</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> ${{ matrix.config.os }} (${{ matrix.config.r }})</span></span>
<span id="cb1-21"></span>
<span id="cb1-22"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">    </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strategy</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb1-23"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">      </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fail-fast</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">false</span></span>
<span id="cb1-24"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">      </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb1-25"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">        </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">config</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb1-26"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">          </span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">-</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">{</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">os</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> macos-latest</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">,</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">   </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'release'</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">}</span></span>
<span id="cb1-27"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">          </span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">-</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">{</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">os</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> windows-latest</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">,</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'release'</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">}</span></span>
<span id="cb1-28"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">          </span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">-</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">{</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">os</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> ubuntu-latest</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">,</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'release'</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">}</span></span>
<span id="cb1-29"></span>
<span id="cb1-30"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">    </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">env</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb1-31"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">      </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">GITHUB_PAT</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> ${{ secrets.GITHUB_TOKEN }}</span></span>
<span id="cb1-32"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">      </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">R_KEEP_PKG_SOURCE</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">yes</span></span>
<span id="cb1-33"></span>
<span id="cb1-34"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">    </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">steps</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb1-35"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">      </span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">-</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">uses</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> actions/checkout@v4</span></span>
<span id="cb1-36"></span>
<span id="cb1-37"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">      </span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">-</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">uses</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> r-lib/actions/setup-pandoc@v2</span></span>
<span id="cb1-38"></span>
<span id="cb1-39"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">      </span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">-</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">uses</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> r-lib/actions/setup-r@v2</span></span>
<span id="cb1-40"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">        </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">with</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb1-41"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">          </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r-version</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> ${{ matrix.config.r }}</span></span>
<span id="cb1-42"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">          </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">http-user-agent</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> ${{ matrix.config.http-user-agent }}</span></span>
<span id="cb1-43"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">          </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">use-public-rspm</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">true</span></span>
<span id="cb1-44"></span>
<span id="cb1-45"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">      </span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">-</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">uses</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> r-lib/actions/setup-r-dependencies@v2</span></span>
<span id="cb1-46"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">        </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">with</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb1-47"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">          </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">extra-packages</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> any::rcmdcheck</span></span>
<span id="cb1-48"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">          </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">needs</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> check</span></span>
<span id="cb1-49"></span>
<span id="cb1-50"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">      </span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">-</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">uses</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> r-lib/actions/check-r-package@v2</span></span>
<span id="cb1-51"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">        </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">with</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb1-52"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">          </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">upload-snapshots</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">true</span></span>
<span id="cb1-53"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">          </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">build_args</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'c("--no-manual","--compact-vignettes=gs+qpdf")'</span></span></code></pre></div></div>
</details>
<p>Here is a section of the <code>NOTE</code>:</p>
<pre><code>* checking R code for possible problems ... NOTE
check_authorized_users: no visible binding for global variable ‘.data’
  (/Users/runner/work/hubhelpr/hubhelpr/check/hubhelpr.Rcheck/00_pkg_src/hubhelpr/R/check_authorized_users.R:35-47)
check_authorized_users: no visible global function definition for
  ‘na.omit’
  (/Users/runner/work/hubhelpr/hubhelpr/check/hubhelpr.Rcheck/00_pkg_src/hubhelpr/R/check_authorized_users.R:35-47)</code></pre>
<p>For more context, here is the relevant code that the above segment refers to:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">changed_dirs_tbl <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dir =</span> changed_model_ids)</span>
<span id="cb3-2"></span>
<span id="cb3-3">authorization_check <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> changed_dirs_tbl <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-4">    dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(model_metadata, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dir"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na_matches =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"never"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-5">    dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(.data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>dir) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-6">    dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb3-7">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">modifiable =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">all</span>(tidyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">replace_na</span>(.data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>is_model_dir, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)),</span>
<span id="cb3-8">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">actor_authorized =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!!</span>gh_actor <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> .data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>designated_github_users,</span>
<span id="cb3-9">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">authorized_users =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(</span>
<span id="cb3-10">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na.omit</span>(.data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>designated_github_users),</span>
<span id="cb3-11">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">collapse =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span></span>
<span id="cb3-12">        ),</span>
<span id="cb3-13">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">has_authorized_users =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">na.omit</span>(.data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>designated_github_users)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb3-14">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span></span>
<span id="cb3-15">    )</span></code></pre></div></div>
<p>The <code>tidyverse</code> documentation for <code>dplyr</code> has a section on this <code>NOTE</code> (see <a href="https://dplyr.tidyverse.org/articles/in-packages.html" class="uri">https://dplyr.tidyverse.org/articles/in-packages.html</a>). In particular, they write:</p>
<blockquote class="blockquote">
<p>If you’re writing a package and you have a function that uses data masking or tidy selection:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">my_summary_function <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(data) {</span>
<span id="cb4-2"> data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb4-3">   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(grp, x, y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb4-4">   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb4-5">   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(grp) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb4-6">   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(y), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>())</span>
<span id="cb4-7">}</span></code></pre></div></div>
<p>You’ll get an <code>NOTE</code> because <code>R CMD check</code> doesn’t know that <code>dplyr</code> functions use tidy evaluation:</p>
<pre><code>N  checking R code for possible problems
   my_summary_function: no visible binding for global variable ‘grp’, ‘x’, ‘y’
   Undefined global functions or variables:
     grp x y</code></pre>
<p>To eliminate this note:</p>
<ul>
<li>For data masking, import <code>.data</code> from rlang and then use <code>.data$var</code> instead of <code>var</code>.</li>
<li>For tidy selection, use <code>"var"</code> instead of <code>var</code>.</li>
</ul>
<p>That yields:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @importFrom rlang .data</span></span>
<span id="cb6-2">my_summary_function <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(data) {</span>
<span id="cb6-3">  data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grp"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(.data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(.data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>grp) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(.data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>y), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>())</span>
<span id="cb6-8">}</span></code></pre></div></div>
</blockquote>
<p>If I wanted to simply get rid of the <code>NOTE</code>, I could add <code>@importFrom rlang .data</code> to my problematic file and then import <code>rlang</code> in my <code>DESCRIPTION</code> file. Before exploring this further through a small example, I wanted to see what <code>rlang</code> had to say.</p>
<p>Both <a href="https://rlang.r-lib.org/" class="uri">https://rlang.r-lib.org/</a> and <a href="https://rlang.r-lib.org/reference/topic-data-mask.html" class="uri">https://rlang.r-lib.org/reference/topic-data-mask.html</a> provide copious and somewhat interesting reference information. These statements (which you can read about further) in the latter article, seemed more relevant:</p>
<blockquote class="blockquote">
<p>To keep these objects and functions in scope, the data frame is inserted at the bottom of the current chain of environments. It comes first and has precedence over the user environment. In other words, it masks the user environment.</p>
</blockquote>
<p>and</p>
<blockquote class="blockquote">
<p>The tidyverse embraced the data-masking approach in packages like ggplot2 and dplyr and eventually developed its own programming framework in the rlang package. None of this would have been possible without the following landmark developments from S and R authors.</p>
</blockquote>
<p>For the example, I need the following:</p>
<ul>
<li>An <code>R-CMD-check.yaml</code> workflow file (see dropdown above).</li>
<li>An R package using <code>dplyr</code>.</li>
</ul>
<p>Steps:</p>
<ul>
<li>In <code>R</code>, run: <code>install.packages(c("devtools", "roxygen2")</code>.</li>
</ul>
<p>REMAINDER PENDING.</p>


<!-- -->


 ]]></description>
  <category>R</category>
  <category>tidyr</category>
  <guid>https://o957.github.io/O957-TIL/posts/r_handle_unbound_tidyr_variables.html</guid>
  <pubDate>Sun, 30 Nov 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Find Empty PDFs Using Pathlib</title>
  <link>https://o957.github.io/O957-TIL/posts/python_find_empty_pdfs_using_pathlib.html</link>
  <description><![CDATA[ 





<p><em>Today I Learned added on 2025-11-20, learned on 2025-11-19; edited on 2026-06-14.</em></p>
<p>In generating routine forecast visualizations yesterday, I received an error thrown by <code>pypdf</code>, which indicated that the a PDF I was processing was empty (the forecast visualizations are aggregated into PDFs). After checking the usual things (i.e.&nbsp;that the internal R package was in fact up-to-date an installed and that I was logged-in and authenticated by Azure), I determined that I needed to actually find the empty PDF to resolve the error.</p>
<p>Since this seems common enough an issue, I expected there to be some one-line Python solutions. The solution I came up with may not be the best in terms of length or speed, but it worked for my use case:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pathlib</span>
<span id="cb1-2"></span>
<span id="cb1-3"></span>
<span id="cb1-4">pdf_files <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [f <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> pathlib.Path(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"."</span>).rglob(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"*.pdf"</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> f.stat().st_size <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]</span></code></pre></div></div>
<p>This line recursively gets all PDF files in the current (<code>"."</code>) directory and all its sub-directories and adds them to the list if the size of the file is 0 (<code>if f.stat().st_size == 0</code>).</p>


<!-- -->


 ]]></description>
  <category>python</category>
  <category>pdf</category>
  <category>pathlib</category>
  <guid>https://o957.github.io/O957-TIL/posts/python_find_empty_pdfs_using_pathlib.html</guid>
  <pubDate>Thu, 20 Nov 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Check CSV Equivalence Using Polars</title>
  <link>https://o957.github.io/O957-TIL/posts/python_check_csv_equivalence_using_polars.html</link>
  <description><![CDATA[ 





<p><em>Today I Learned added on 2025-11-20, learned on 2025-11-20; edited on 2026-06-14.</em></p>
<p>I found myself reviewing two PRs made by the same individual and each PR had a <code>csv</code> file containing forecasts. The <code>csv</code>s seemed identical, but I wasn’t sure, so I wanted a way to check for equivalence using Python.</p>
<p>Given that, at present, I prefer <code>polars</code> over <code>pandas</code>, I searched <code>polars</code> for a method and found the method <code>equals</code> (see <a href="https://docs.pola.rs/api/python/stable/reference/dataframe/api/polars.DataFrame.equals.html" class="uri">https://docs.pola.rs/api/python/stable/reference/dataframe/api/polars.DataFrame.equals.html</a>) in the <code>DataFrame</code> class .</p>
<p>Example <code>csv</code> file as <code>example_01.csv</code>:</p>
<pre><code>column_1,column_2
45,98
32,31
17,100</code></pre>
<p>Example <code>csv</code> file as <code>example_02.csv</code>:</p>
<pre><code>column_1,column_2
87,98
32,31
17,100</code></pre>
<p>First, the non-Python, Unix command <code>diff</code> (the standard method I’ve employed for equivalence testing) can also be used.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">diff</span> example_01.csv example_02.csv</span>
<span id="cb3-2"></span>
<span id="cb3-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># output:</span></span>
<span id="cb3-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 2c2</span></span>
<span id="cb3-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># &lt; 45,98</span></span>
<span id="cb3-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ---</span></span>
<span id="cb3-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># &gt; 87,98</span></span></code></pre></div></div>
<p>In Python, using the <code>equals</code> method of <code>polars</code>, which outputs <code>True</code> or <code>False</code>, instead of the actual differences if there are any:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> polars <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pl</span>
<span id="cb4-2"></span>
<span id="cb4-3"></span>
<span id="cb4-4">df_01 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pl.read_csv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"example_01.csv"</span>)</span>
<span id="cb4-5">df_02 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pl.read_csv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"example_02.csv"</span>)</span>
<span id="cb4-6"></span>
<span id="cb4-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># output: False</span></span>
<span id="cb4-8">df_01.equals(df_02)</span></code></pre></div></div>


<!-- -->


 ]]></description>
  <category>python</category>
  <category>csv</category>
  <category>polars</category>
  <guid>https://o957.github.io/O957-TIL/posts/python_check_csv_equivalence_using_polars.html</guid>
  <pubDate>Thu, 20 Nov 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Uniformly Partitioning A String Using Textwrap</title>
  <link>https://o957.github.io/O957-TIL/posts/python_uniformly_partitioning_a_string_textwrap.html</link>
  <description><![CDATA[ 





<p><em>Today I Learned added on 2025-11-13, learned on 2025-11-08; edited on 2026-06-14.</em></p>
<p>A merchant on Ebay sent me a list of item ID codes (each 12 characters long) as a newline separated list. When I copied and pasted the list into a text file (to have two separate windows open at once), the characters were concatenated into a single string — how annoying! I tried different types of copying-and-pasting (pasting using <code>Cmd-V</code> and <code>Cmd-Shift-V</code>) to no avail. I then wondered if Python could help me avoid manually cutting out each 12 character string from the single long string. The answer is “Yes!” and there is a package called <code>textwrap</code> that can help with this task specifically.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># concatenated str</span></span>
<span id="cb1-2">c_str <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"432853242343242343242342343243276575"</span></span>
<span id="cb1-3"></span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># partition size</span></span>
<span id="cb1-5">p_size  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span></span>
<span id="cb1-6"></span>
<span id="cb1-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># uniformly partitioned string; ['432853242343', '242343242342', '343243276575']</span></span>
<span id="cb1-8">up_str <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [c_str[i:i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>p_size] <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> i <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(c_str),  p_size) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(c_str) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> p_size <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]</span></code></pre></div></div>
<p>The simpler method is to use Python’s <code>textwrap</code> package:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> textwrap</span>
<span id="cb2-2"></span>
<span id="cb2-3"></span>
<span id="cb2-4">c_str <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"432853242343242343242342343243276575"</span></span>
<span id="cb2-5"></span>
<span id="cb2-6">p_size  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span></span>
<span id="cb2-7"></span>
<span id="cb2-8"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(c_str) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> p_size <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>:</span>
<span id="cb2-9">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ['432853242343', '242343242342', '343243276575']</span></span>
<span id="cb2-10">    up_str <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> textwrap.wrap(c_str, p_size)</span></code></pre></div></div>


<!-- -->


 ]]></description>
  <category>python</category>
  <category>textwrap</category>
  <guid>https://o957.github.io/O957-TIL/posts/python_uniformly_partitioning_a_string_textwrap.html</guid>
  <pubDate>Thu, 13 Nov 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Get The Remaining Dates In A Year Using Datetime</title>
  <link>https://o957.github.io/O957-TIL/posts/python_get_remaining_dates_in_year_using_datetime.html</link>
  <description><![CDATA[ 





<p><em>Today I Learned added on 2025-11-13, learned on 2025-11-11; edited on 2026-06-14.</em></p>
<p>Suppose you want to see how many dates there are remaining in the current year or, better yet, want a <code>list</code> of all of the remaining dates in the current year.</p>
<p>The Python package <code>datetime</code>, which is Python’s built-in date and time manipulation package (<a href="https://docs.python.org/3/library/datetime.html" class="uri">https://docs.python.org/3/library/datetime.html</a>), allows one to do this rather easily.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> datetime</span>
<span id="cb1-2"></span>
<span id="cb1-3"></span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># out: datetime.date(2025, 11, 13)</span></span>
<span id="cb1-5">today <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> datetime.date.today()</span>
<span id="cb1-6"></span>
<span id="cb1-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># out: datetime.date(2025, 12, 31)</span></span>
<span id="cb1-8">end_of_year <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> today.replace(month<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, day<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">31</span>)</span>
<span id="cb1-9"></span>
<span id="cb1-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># out: 49</span></span>
<span id="cb1-11">remaining_days_in_year <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (end_of_year <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> today).days <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb1-12"></span>
<span id="cb1-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># out: ['2025-11-13', '2025-11-14', ..., '2025-12-31']</span></span>
<span id="cb1-14">remaining_dates_in_year <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [today <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> datetime.timedelta(days<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>d).strftime(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y-%m-</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%d</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(remaining_days_in_year)]</span></code></pre></div></div>
<p>I became interested in this originally when I wanted to create text files for my notes for the remainder of the year. I use files entitled <code>Notes_For_YYYY-DD-MM</code> containing a template (e.g.&nbsp;Todos, Daily Plan, etc…) and the task boiled down to getting the remaining <a href="https://en.wikipedia.org/wiki/ISO_8601">ISO-8601</a> formatted dates in the current year. The full program can be found below:</p>
<details>
<summary>
Notes File Generator
</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb2-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">Script for getting the remaining dates (formatted as</span></span>
<span id="cb2-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">ISO-8601 strings) in the current year and creating</span></span>
<span id="cb2-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">daily note files from a template.</span></span>
<span id="cb2-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb2-6"></span>
<span id="cb2-7"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> datetime <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> date, timedelta</span>
<span id="cb2-8"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb2-9"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> sys</span>
<span id="cb2-10"></span>
<span id="cb2-11"></span>
<span id="cb2-12"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> get_remaining_dates(year: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-&gt;</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">list</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>]:</span>
<span id="cb2-13">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb2-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    Get all remaining dates in the specified year as</span></span>
<span id="cb2-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    ISO-8601 strings.</span></span>
<span id="cb2-16"></span>
<span id="cb2-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    Parameters</span></span>
<span id="cb2-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    ----------</span></span>
<span id="cb2-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    year : int</span></span>
<span id="cb2-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">        The year to get remaining dates for.</span></span>
<span id="cb2-21"></span>
<span id="cb2-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    Returns</span></span>
<span id="cb2-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    -------</span></span>
<span id="cb2-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    list[str]</span></span>
<span id="cb2-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">        List of date strings in YYYY-MM-DD format.</span></span>
<span id="cb2-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    """</span></span>
<span id="cb2-27">    today <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> date.today()</span>
<span id="cb2-28">    end_of_year <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> date(year, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">31</span>)</span>
<span id="cb2-29">    days_remaining <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (end_of_year <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> today).days <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb2-30">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> [(today <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> timedelta(days<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>i)).strftime(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y-%m-</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%d</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> i <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(days_remaining)]</span>
<span id="cb2-31"></span>
<span id="cb2-32"></span>
<span id="cb2-33"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_template(filename: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-&gt;</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>:</span>
<span id="cb2-34">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb2-35"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    Read the notes template file.</span></span>
<span id="cb2-36"></span>
<span id="cb2-37"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    Parameters</span></span>
<span id="cb2-38"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    ----------</span></span>
<span id="cb2-39"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    filename : str</span></span>
<span id="cb2-40"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">        Path to the template file.</span></span>
<span id="cb2-41"></span>
<span id="cb2-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    Returns</span></span>
<span id="cb2-43"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    -------</span></span>
<span id="cb2-44"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    str</span></span>
<span id="cb2-45"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">        Template content.</span></span>
<span id="cb2-46"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    """</span></span>
<span id="cb2-47">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">try</span>:</span>
<span id="cb2-48">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">with</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">open</span>(filename, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"r"</span>) <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> f:</span>
<span id="cb2-49">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> f.read()</span>
<span id="cb2-50">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">except</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">FileNotFoundError</span>:</span>
<span id="cb2-51">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Error: Template file '</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>filename<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">' not found."</span>)</span>
<span id="cb2-52">        sys.exit(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb2-53">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">except</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">IOError</span> <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> e:</span>
<span id="cb2-54">        <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Error reading template file: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>e<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb2-55">        sys.exit(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb2-56"></span>
<span id="cb2-57"></span>
<span id="cb2-58"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> create_note_files(dates: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">list</span>[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>], template: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>, prefix: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Notes_For_"</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-&gt;</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>:</span>
<span id="cb2-59">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb2-60"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    Create note files for each date if they don't</span></span>
<span id="cb2-61"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    already exist.</span></span>
<span id="cb2-62"></span>
<span id="cb2-63"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    Parameters</span></span>
<span id="cb2-64"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    ----------</span></span>
<span id="cb2-65"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    dates : list[str]</span></span>
<span id="cb2-66"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">        List of date strings to create files for.</span></span>
<span id="cb2-67"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    template : str</span></span>
<span id="cb2-68"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">        Template content to write to each file.</span></span>
<span id="cb2-69"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    prefix : str</span></span>
<span id="cb2-70"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">        Filename prefix for note files.</span></span>
<span id="cb2-71"></span>
<span id="cb2-72"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    Returns</span></span>
<span id="cb2-73"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    -------</span></span>
<span id="cb2-74"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    int</span></span>
<span id="cb2-75"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">        Number of files created.</span></span>
<span id="cb2-76"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    """</span></span>
<span id="cb2-77">    created_count <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb2-78">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> dates:</span>
<span id="cb2-79">        filename <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>prefix<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}{</span>d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">.txt"</span></span>
<span id="cb2-80">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">not</span> os.path.exists(filename):</span>
<span id="cb2-81">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">with</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">open</span>(filename, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"w"</span>) <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> f:</span>
<span id="cb2-82">                f.write(template)</span>
<span id="cb2-83">            created_count <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb2-84"></span>
<span id="cb2-85">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> created_count</span>
<span id="cb2-86"></span>
<span id="cb2-87"></span>
<span id="cb2-88"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">__name__</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"__main__"</span>:</span>
<span id="cb2-89">    current_year <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> date.today().year</span>
<span id="cb2-90">    remaining_dates <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> get_remaining_dates(current_year)</span>
<span id="cb2-91">    template <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_template(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NOTES.txt"</span>)</span>
<span id="cb2-92">    created <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> create_note_files(remaining_dates, template)</span>
<span id="cb2-93">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Created </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>created<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> new note files for the remaining days of </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>current_year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">."</span>)</span></code></pre></div></div>
</details>


<!-- -->


 ]]></description>
  <category>python</category>
  <category>datetime</category>
  <guid>https://o957.github.io/O957-TIL/posts/python_get_remaining_dates_in_year_using_datetime.html</guid>
  <pubDate>Tue, 11 Nov 2025 00:00:00 GMT</pubDate>
</item>
</channel>
</rss>
