sam | science
  • About
Categories
All (6)
Apache Arrow (1)
JavaScript (1)
ObservableJS (1)
R (6)
RStudio (1)
api (1)
hydrology (2)
music (1)
nhl (1)
python (1)
task-view (1)
tidyhydat (1)

 

I Scream, You Scream, We All Scream for an Arrow Schema

R
Apache Arrow
python
Always take the time to write a schema. Sometimes you have to. It is isn’t optional. But in less strongly typed languages like R and python, you can sometimes get away with…
Oct 2, 2024
Sam Albers

Talking (Hockey) Age with ObservableJS

R
JavaScript
ObservableJS
nhl
api
Lately I’ve been thinking about two things: getting old and ObservableJS. Getting old is self-explanatory. ObservableJS (ojs) is maybe less so. Normally ojs is used in a Java…
Oct 1, 2024
Sam Albers

 

The return of the web service

R
hydrology
tidyhydat
The most common question I get about the tidyhydat package goes something like this:
May 4, 2023
Sam Albers

A short history of me at rstudio::conf 2020

R
RStudio
In January, I was lucky enough to attend the 2020 edition of RStudio::conf. Perhaps predictably, the conference and workshops were exceptional and to see all the wonderful…
Feb 11, 2020
Sam Albers

One small step for a package, one giant leap for a task view

hydrology
task-view
R
This is a bit of a grandiose title for a blog post. But it is important to have ambition right? In 2003, after releasing Michigan, Sufjan Stevens announced his intention to…
Jan 19, 2020
Sam Albers

Wikimedia Error<%2Ftitle> <style> * { margin%3A 0%3B padding%3A 0%3B } body { background%3A %23fff%3B font%3A 15px%2F1.6 sans-serif%3B color%3A %23333%3B } .content { margin%3A 7% auto 0%3B padding%3A 2em 1em 1em%3B max-width%3A 640px%3B } .footer { clear%3A both%3B margin-top%3A 14%%3B border-top%3A 1px solid %23e5e5e5%3B background%3A %23f9f9f9%3B padding%3A 2em 0%3B font-size%3A 0.8em%3B text-align%3A center%3B } img { float%3A left%3B margin%3A 0 2em 2em 0%3B } a img { border%3A 0%3B } h1 { margin-top%3A 1em%3B font-size%3A 1.2em%3B } .content-text { overflow%3A hidden%3B overflow-wrap%3A break-word%3B word-wrap%3A break-word%3B -webkit-hyphens%3A auto%3B -moz-hyphens%3A auto%3B -ms-hyphens%3A auto%3B hyphens%3A auto%3B } p { margin%3A 0.7em 0 1em 0%3B } a { color%3A %230645ad%3B text-decoration%3A none%3B } a%3Ahover { text-decoration%3A underline%3B } code { font-family%3A sans-serif%3B } .text-muted { color%3A %23777%3B } %40media (prefers-color-scheme%3A dark) { a { color%3A %239e9eff%3B } body { background%3A transparent%3B color%3A %23ddd%3B } .footer { border-top%3A 1px solid %23444%3B background%3A %23060606%3B } %23logo { filter%3A invert(1) hue-rotate(180deg)%3B } .text-muted { color%3A %23888%3B } } <%2Fstyle> <meta name%3D"color-scheme" content%3D"light dark"> <div class%3D"content" role%3D"main"> <a href%3D"https%3A%2F%2Fwww.wikimedia.org"><img id%3D"logo" src%3D"https%3A%2F%2Fwww.wikimedia.org%2Fstatic%2Fimages%2Fwmf-logo.png" srcset%3D"https%3A%2F%2Fwww.wikimedia.org%2Fstatic%2Fimages%2Fwmf-logo-2x.png 2x" alt%3D"Wikimedia" width%3D"135" height%3D"101"> <%2Fa> <h1>Error<%2Fh1> <div class%3D"content-text"> <p>Our servers are currently under maintenance or experiencing a technical issue<%2Fp> <%2Fdiv> <%2Fdiv> <div class%3D"footer"><p>If you report this error to the Wikimedia System Administrators%2C please include the details below.<%2Fp><p class%3D"text-muted"><code>Request from 2001%3A569%3Abebd%3A5500%3A7c41%3A5bd6%3A36b4%3A58af via cp4048 cp4048%2C Varnish XID 266204690<br>Upstream caches%3A cp4048 int<br>Error%3A 403%2C Forbidden. Please comply with the User-Agent policy%3A https%3A%2F%2Fmeta.wikimedia.org%2Fwiki%2FUser-Agent_policy at Wed%2C 02 Oct 2024 14%3A57%3A41 GMT<%2Fcode><%2Fp> <%2Fdiv> <%2Fhtml> " class="thumbnail-image card-img"/></p> </a><p><a class='no-external' href='/posts/2019-11-17-what-the-buck/'></a></p> </div> <div class="body"> <h3 class="no-anchor listing-title"> <a class='no-external' href='/posts/2019-11-17-what-the-buck/'>What the Buck?</a> </h3> <div class="listing-subtitle"> <a class='no-external' href='/posts/2019-11-17-what-the-buck/'></a> </div> <div class="listing-categories"> <div class="listing-category" onclick="window.quartoListingCategory('music'); return false;"> music </div> <div class="listing-category" onclick="window.quartoListingCategory('R'); return false;"> R </div> </div> <div class="listing-description"> <a class='no-external' href='/posts/2019-11-17-what-the-buck/'>Buck talk</a> </div> </div> <div class="metadata"> <a class='no-external' href='/posts/2019-11-17-what-the-buck/'> <div class="listing-date"> Nov 17, 2019 </div> <div class="listing-author"> Sam Albers </div> </a> </div> </div> </div> <div class="listing-no-matching d-none"> No matching items </div> </div></main> <!-- /main --> <script id="quarto-html-after-body" type="application/javascript"> window.document.addEventListener("DOMContentLoaded", function (event) { const toggleBodyColorMode = (bsSheetEl) => { const mode = bsSheetEl.getAttribute("data-mode"); const bodyEl = window.document.querySelector("body"); if (mode === "dark") { bodyEl.classList.add("quarto-dark"); bodyEl.classList.remove("quarto-light"); } else { bodyEl.classList.add("quarto-light"); bodyEl.classList.remove("quarto-dark"); } } const toggleBodyColorPrimary = () => { const bsSheetEl = window.document.querySelector("link#quarto-bootstrap"); if (bsSheetEl) { toggleBodyColorMode(bsSheetEl); } } toggleBodyColorPrimary(); const disableStylesheet = (stylesheets) => { for (let i=0; i < stylesheets.length; i++) { const stylesheet = stylesheets[i]; stylesheet.rel = 'prefetch'; } } const enableStylesheet = (stylesheets) => { for (let i=0; i < stylesheets.length; i++) { const stylesheet = stylesheets[i]; stylesheet.rel = 'stylesheet'; } } const manageTransitions = (selector, allowTransitions) => { const els = window.document.querySelectorAll(selector); for (let i=0; i < els.length; i++) { const el = els[i]; if (allowTransitions) { el.classList.remove('notransition'); } else { el.classList.add('notransition'); } } } const toggleGiscusIfUsed = (isAlternate, darkModeDefault) => { const baseTheme = document.querySelector('#giscus-base-theme')?.value ?? 'light'; const alternateTheme = document.querySelector('#giscus-alt-theme')?.value ?? 'dark'; let newTheme = ''; if(darkModeDefault) { newTheme = isAlternate ? baseTheme : alternateTheme; } else { newTheme = isAlternate ? alternateTheme : baseTheme; } const changeGiscusTheme = () => { // From: https://github.com/giscus/giscus/issues/336 const sendMessage = (message) => { const iframe = document.querySelector('iframe.giscus-frame'); if (!iframe) return; iframe.contentWindow.postMessage({ giscus: message }, 'https://giscus.app'); } sendMessage({ setConfig: { theme: newTheme } }); } const isGiscussLoaded = window.document.querySelector('iframe.giscus-frame') !== null; if (isGiscussLoaded) { changeGiscusTheme(); } } const toggleColorMode = (alternate) => { // Switch the stylesheets const alternateStylesheets = window.document.querySelectorAll('link.quarto-color-scheme.quarto-color-alternate'); manageTransitions('#quarto-margin-sidebar .nav-link', false); if (alternate) { enableStylesheet(alternateStylesheets); for (const sheetNode of alternateStylesheets) { if (sheetNode.id === "quarto-bootstrap") { toggleBodyColorMode(sheetNode); } } } else { disableStylesheet(alternateStylesheets); toggleBodyColorPrimary(); } manageTransitions('#quarto-margin-sidebar .nav-link', true); // Switch the toggles const toggles = window.document.querySelectorAll('.quarto-color-scheme-toggle'); for (let i=0; i < toggles.length; i++) { const toggle = toggles[i]; if (toggle) { if (alternate) { toggle.classList.add("alternate"); } else { toggle.classList.remove("alternate"); } } } // Hack to workaround the fact that safari doesn't // properly recolor the scrollbar when toggling (#1455) if (navigator.userAgent.indexOf('Safari') > 0 && navigator.userAgent.indexOf('Chrome') == -1) { manageTransitions("body", false); window.scrollTo(0, 1); setTimeout(() => { window.scrollTo(0, 0); manageTransitions("body", true); }, 40); } } const isFileUrl = () => { return window.location.protocol === 'file:'; } const hasAlternateSentinel = () => { let styleSentinel = getColorSchemeSentinel(); if (styleSentinel !== null) { return styleSentinel === "alternate"; } else { return false; } } const setStyleSentinel = (alternate) => { const value = alternate ? "alternate" : "default"; if (!isFileUrl()) { window.localStorage.setItem("quarto-color-scheme", value); } else { localAlternateSentinel = value; } } const getColorSchemeSentinel = () => { if (!isFileUrl()) { const storageValue = window.localStorage.getItem("quarto-color-scheme"); return storageValue != null ? storageValue : localAlternateSentinel; } else { return localAlternateSentinel; } } const darkModeDefault = false; let localAlternateSentinel = darkModeDefault ? 'alternate' : 'default'; // Dark / light mode switch window.quartoToggleColorScheme = () => { // Read the current dark / light value let toAlternate = !hasAlternateSentinel(); toggleColorMode(toAlternate); setStyleSentinel(toAlternate); toggleGiscusIfUsed(toAlternate, darkModeDefault); }; // Ensure there is a toggle, if there isn't float one in the top right if (window.document.querySelector('.quarto-color-scheme-toggle') === null) { const a = window.document.createElement('a'); a.classList.add('top-right'); a.classList.add('quarto-color-scheme-toggle'); a.href = ""; a.onclick = function() { try { window.quartoToggleColorScheme(); } catch {} return false; }; const i = window.document.createElement("i"); i.classList.add('bi'); a.appendChild(i); window.document.body.appendChild(a); } // Switch to dark mode if need be if (hasAlternateSentinel()) { toggleColorMode(true); } else { toggleColorMode(false); } const icon = ""; const anchorJS = new window.AnchorJS(); anchorJS.options = { placement: 'right', icon: icon }; anchorJS.add('.anchored'); const isCodeAnnotation = (el) => { for (const clz of el.classList) { if (clz.startsWith('code-annotation-')) { return true; } } return false; } const onCopySuccess = function(e) { // button target const button = e.trigger; // don't keep focus button.blur(); // flash "checked" button.classList.add('code-copy-button-checked'); var currentTitle = button.getAttribute("title"); button.setAttribute("title", "Copied!"); let tooltip; if (window.bootstrap) { button.setAttribute("data-bs-toggle", "tooltip"); button.setAttribute("data-bs-placement", "left"); button.setAttribute("data-bs-title", "Copied!"); tooltip = new bootstrap.Tooltip(button, { trigger: "manual", customClass: "code-copy-button-tooltip", offset: [0, -8]}); tooltip.show(); } setTimeout(function() { if (tooltip) { tooltip.hide(); button.removeAttribute("data-bs-title"); button.removeAttribute("data-bs-toggle"); button.removeAttribute("data-bs-placement"); } button.setAttribute("title", currentTitle); button.classList.remove('code-copy-button-checked'); }, 1000); // clear code selection e.clearSelection(); } const getTextToCopy = function(trigger) { const codeEl = trigger.previousElementSibling.cloneNode(true); for (const childEl of codeEl.children) { if (isCodeAnnotation(childEl)) { childEl.remove(); } } return codeEl.innerText; } const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', { text: getTextToCopy }); clipboard.on('success', onCopySuccess); if (window.document.getElementById('quarto-embedded-source-code-modal')) { // For code content inside modals, clipBoardJS needs to be initialized with a container option // TODO: Check when it could be a function (https://github.com/zenorocha/clipboard.js/issues/860) const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', { text: getTextToCopy, container: window.document.getElementById('quarto-embedded-source-code-modal') }); clipboardModal.on('success', onCopySuccess); } var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//); var mailtoRegex = new RegExp(/^mailto:/); var filterRegex = new RegExp("https:\/\/samalbers\.science"); var isInternal = (href) => { return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href); } // Inspect non-navigation links and adorn them if external var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool):not(.about-link)'); for (var i=0; i<links.length; i++) { const link = links[i]; if (!isInternal(link.href)) { // undo the damage that might have been done by quarto-nav.js in the case of // links that we want to consider external if (link.dataset.originalHref !== undefined) { link.href = link.dataset.originalHref; } // target, if specified link.setAttribute("target", "_blank"); if (link.getAttribute("rel") === null) { link.setAttribute("rel", "noopener"); } } } function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) { const config = { allowHTML: true, maxWidth: 500, delay: 100, arrow: false, appendTo: function(el) { return el.parentElement; }, interactive: true, interactiveBorder: 10, theme: 'quarto', placement: 'bottom-start', }; if (contentFn) { config.content = contentFn; } if (onTriggerFn) { config.onTrigger = onTriggerFn; } if (onUntriggerFn) { config.onUntrigger = onUntriggerFn; } window.tippy(el, config); } const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]'); for (var i=0; i<noterefs.length; i++) { const ref = noterefs[i]; tippyHover(ref, function() { // use id or data attribute instead here let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href'); try { href = new URL(href).hash; } catch {} const id = href.replace(/^#\/?/, ""); const note = window.document.getElementById(id); if (note) { return note.innerHTML; } else { return ""; } }); } const xrefs = window.document.querySelectorAll('a.quarto-xref'); const processXRef = (id, note) => { // Strip column container classes const stripColumnClz = (el) => { el.classList.remove("page-full", "page-columns"); if (el.children) { for (const child of el.children) { stripColumnClz(child); } } } stripColumnClz(note) if (id === null || id.startsWith('sec-')) { // Special case sections, only their first couple elements const container = document.createElement("div"); if (note.children && note.children.length > 2) { container.appendChild(note.children[0].cloneNode(true)); for (let i = 1; i < note.children.length; i++) { const child = note.children[i]; if (child.tagName === "P" && child.innerText === "") { continue; } else { container.appendChild(child.cloneNode(true)); break; } } if (window.Quarto?.typesetMath) { window.Quarto.typesetMath(container); } return container.innerHTML } else { if (window.Quarto?.typesetMath) { window.Quarto.typesetMath(note); } return note.innerHTML; } } else { // Remove any anchor links if they are present const anchorLink = note.querySelector('a.anchorjs-link'); if (anchorLink) { anchorLink.remove(); } if (window.Quarto?.typesetMath) { window.Quarto.typesetMath(note); } // TODO in 1.5, we should make sure this works without a callout special case if (note.classList.contains("callout")) { return note.outerHTML; } else { return note.innerHTML; } } } for (var i=0; i<xrefs.length; i++) { const xref = xrefs[i]; tippyHover(xref, undefined, function(instance) { instance.disable(); let url = xref.getAttribute('href'); let hash = undefined; if (url.startsWith('#')) { hash = url; } else { try { hash = new URL(url).hash; } catch {} } if (hash) { const id = hash.replace(/^#\/?/, ""); const note = window.document.getElementById(id); if (note !== null) { try { const html = processXRef(id, note.cloneNode(true)); instance.setContent(html); } finally { instance.enable(); instance.show(); } } else { // See if we can fetch this fetch(url.split('#')[0]) .then(res => res.text()) .then(html => { const parser = new DOMParser(); const htmlDoc = parser.parseFromString(html, "text/html"); const note = htmlDoc.getElementById(id); if (note !== null) { const html = processXRef(id, note); instance.setContent(html); } }).finally(() => { instance.enable(); instance.show(); }); } } else { // See if we can fetch a full url (with no hash to target) // This is a special case and we should probably do some content thinning / targeting fetch(url) .then(res => res.text()) .then(html => { const parser = new DOMParser(); const htmlDoc = parser.parseFromString(html, "text/html"); const note = htmlDoc.querySelector('main.content'); if (note !== null) { // This should only happen for chapter cross references // (since there is no id in the URL) // remove the first header if (note.children.length > 0 && note.children[0].tagName === "HEADER") { note.children[0].remove(); } const html = processXRef(null, note); instance.setContent(html); } }).finally(() => { instance.enable(); instance.show(); }); } }, function(instance) { }); } let selectedAnnoteEl; const selectorForAnnotation = ( cell, annotation) => { let cellAttr = 'data-code-cell="' + cell + '"'; let lineAttr = 'data-code-annotation="' + annotation + '"'; const selector = 'span[' + cellAttr + '][' + lineAttr + ']'; return selector; } const selectCodeLines = (annoteEl) => { const doc = window.document; const targetCell = annoteEl.getAttribute("data-target-cell"); const targetAnnotation = annoteEl.getAttribute("data-target-annotation"); const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation)); const lines = annoteSpan.getAttribute("data-code-lines").split(","); const lineIds = lines.map((line) => { return targetCell + "-" + line; }) let top = null; let height = null; let parent = null; if (lineIds.length > 0) { //compute the position of the single el (top and bottom and make a div) const el = window.document.getElementById(lineIds[0]); top = el.offsetTop; height = el.offsetHeight; parent = el.parentElement.parentElement; if (lineIds.length > 1) { const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]); const bottom = lastEl.offsetTop + lastEl.offsetHeight; height = bottom - top; } if (top !== null && height !== null && parent !== null) { // cook up a div (if necessary) and position it let div = window.document.getElementById("code-annotation-line-highlight"); if (div === null) { div = window.document.createElement("div"); div.setAttribute("id", "code-annotation-line-highlight"); div.style.position = 'absolute'; parent.appendChild(div); } div.style.top = top - 2 + "px"; div.style.height = height + 4 + "px"; div.style.left = 0; let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter"); if (gutterDiv === null) { gutterDiv = window.document.createElement("div"); gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter"); gutterDiv.style.position = 'absolute'; const codeCell = window.document.getElementById(targetCell); const gutter = codeCell.querySelector('.code-annotation-gutter'); gutter.appendChild(gutterDiv); } gutterDiv.style.top = top - 2 + "px"; gutterDiv.style.height = height + 4 + "px"; } selectedAnnoteEl = annoteEl; } }; const unselectCodeLines = () => { const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"]; elementsIds.forEach((elId) => { const div = window.document.getElementById(elId); if (div) { div.remove(); } }); selectedAnnoteEl = undefined; }; // Handle positioning of the toggle window.addEventListener( "resize", throttle(() => { elRect = undefined; if (selectedAnnoteEl) { selectCodeLines(selectedAnnoteEl); } }, 10) ); function throttle(fn, ms) { let throttle = false; let timer; return (...args) => { if(!throttle) { // first call gets through fn.apply(this, args); throttle = true; } else { // all the others get throttled if(timer) clearTimeout(timer); // cancel #2 timer = setTimeout(() => { fn.apply(this, args); timer = throttle = false; }, ms); } }; } // Attach click handler to the DT const annoteDls = window.document.querySelectorAll('dt[data-target-cell]'); for (const annoteDlNode of annoteDls) { annoteDlNode.addEventListener('click', (event) => { const clickedEl = event.target; if (clickedEl !== selectedAnnoteEl) { unselectCodeLines(); const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active'); if (activeEl) { activeEl.classList.remove('code-annotation-active'); } selectCodeLines(clickedEl); clickedEl.classList.add('code-annotation-active'); } else { // Unselect the line unselectCodeLines(); clickedEl.classList.remove('code-annotation-active'); } }); } const findCites = (el) => { const parentEl = el.parentElement; if (parentEl) { const cites = parentEl.dataset.cites; if (cites) { return { el, cites: cites.split(' ') }; } else { return findCites(el.parentElement) } } else { return undefined; } }; var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]'); for (var i=0; i<bibliorefs.length; i++) { const ref = bibliorefs[i]; const citeInfo = findCites(ref); if (citeInfo) { tippyHover(citeInfo.el, function() { var popup = window.document.createElement('div'); citeInfo.cites.forEach(function(cite) { var citeDiv = window.document.createElement('div'); citeDiv.classList.add('hanging-indent'); citeDiv.classList.add('csl-entry'); var biblioDiv = window.document.getElementById('ref-' + cite); if (biblioDiv) { citeDiv.innerHTML = biblioDiv.innerHTML; } popup.appendChild(citeDiv); }); return popup.innerHTML; }); } } }); </script> </div> <!-- /content --> </body></html>