Skip to content

Commit

Permalink
update slides
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-arino committed Dec 26, 2023
1 parent 6a60110 commit b4772e2
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 10 deletions.
54 changes: 48 additions & 6 deletions SLIDES/vignette-03-installing-using-packages.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,67 @@ <h1 id="outline">Outline</h1>
<li>Installing a package</li>
<li>Loading a package</li>
<li>Be friendly to others!</li>
<li>Updating packages</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 960 720"><foreignObject width="960" height="720"><section id="4" data-class="invert" data-background-color="black" data-background-image="linear-gradient(to bottom, #f1c40f, 20%, white)" data-theme="default" lang="en-US" class="invert" style="--class:invert;--background-color:black;--background-image:linear-gradient(to bottom, #f1c40f, 20%, white);--theme:default;background-color:black;background-image:linear-gradient(to bottom, #f1c40f, 20%, white);background-position:center;background-repeat:no-repeat;background-size:cover;" data-size="4:3">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 960 720"><foreignObject width="960" height="720"><section id="4" data-class="invert" data-background-color="black" data-background-image="linear-gradient(to bottom, red, black)" data-theme="default" lang="en-US" class="invert" style="--class:invert;--background-color:black;--background-image:linear-gradient(to bottom, red, black);--theme:default;background-color:black;background-image:linear-gradient(to bottom, red, black);background-position:center;background-repeat:no-repeat;background-size:cover;" data-size="4:3">
<h1 is="marp-h1" data-auto-scaling id="packages-aka-libraries">Packages (a.k.a. libraries)</h1>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 960 720"><foreignObject width="960" height="720"><section id="5" data-class="invert" data-background-color="black" data-theme="default" lang="en-US" class="invert" style="--class:invert;--background-color:black;--theme:default;background-color:black;background-image:none;" data-size="4:3">
<h1 is="marp-h1" data-auto-scaling id="be-friendly-to-others">Be friendly to others!</h1>
<p><em>Packages</em> (also called <em>libraries</em>) extend <code>R</code> by providing functions or data that is useful in particular contexts</p>
<p>Allow to avoid &quot;bloating&quot;, since the <code>R</code> core remains relatively light and you only install the additional content you need</p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 960 720"><foreignObject width="960" height="720"><section id="6" data-class="invert" data-background-color="black" data-theme="default" lang="en-US" class="invert" style="--class:invert;--background-color:black;--theme:default;background-color:black;background-image:none;" data-size="4:3">
<h1 id="cran-is-the-main-source-for-packages">CRAN is the main source for packages</h1>
<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-R"><span class="hljs-operator">&gt;</span> paste<span class="hljs-punctuation">(</span>nrow<span class="hljs-punctuation">(</span>available.packages<span class="hljs-punctuation">(</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">,</span><span class="hljs-string">&quot;on&quot;</span><span class="hljs-punctuation">,</span>Sys.Date<span class="hljs-punctuation">(</span><span class="hljs-punctuation">)</span><span class="hljs-punctuation">)</span>
<span class="hljs-punctuation">[</span><span class="hljs-number">1</span><span class="hljs-punctuation">]</span> <span class="hljs-string">&quot;20240 on 2023-12-26&quot;</span>
</code></pre>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 960 720"><foreignObject width="960" height="720"><section id="7" data-class="invert" data-background-color="black" data-theme="default" lang="en-US" class="invert" style="--class:invert;--background-color:black;--theme:default;background-color:black;background-image:none;" data-size="4:3">
<h1 id="there-are-also-packages-not-on-cran">There are also packages not on CRAN</h1>
<ul>
<li>For instance, packages on GitHub</li>
<li>Sometimes packages get removed from CRAN, although the latest versions are typically still available</li>
<li>Installation is a little different (detailed later)</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 960 720"><foreignObject width="960" height="720"><section id="8" data-class="invert" data-background-color="black" data-background-image="linear-gradient(to bottom, red, black)" data-theme="default" lang="en-US" class="invert" style="--class:invert;--background-color:black;--background-image:linear-gradient(to bottom, red, black);--theme:default;background-color:black;background-image:linear-gradient(to bottom, red, black);background-position:center;background-repeat:no-repeat;background-size:cover;" data-size="4:3">
<h1 is="marp-h1" data-auto-scaling id="installing-a-package">Installing a package</h1>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 960 720"><foreignObject width="960" height="720"><section id="9" data-class="invert" data-background-color="black" data-theme="default" lang="en-US" class="invert" style="--class:invert;--background-color:black;--theme:default;background-color:black;background-image:none;" data-size="4:3">
<h1 id="from-cran">From CRAN</h1>
<p><code>install.packages()</code></p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 960 720"><foreignObject width="960" height="720"><section id="10" data-class="invert" data-background-color="black" data-background-image="linear-gradient(to bottom, red, black)" data-theme="default" lang="en-US" class="invert" style="--class:invert;--background-color:black;--background-image:linear-gradient(to bottom, red, black);--theme:default;background-color:black;background-image:linear-gradient(to bottom, red, black);background-position:center;background-repeat:no-repeat;background-size:cover;" data-size="4:3">
<h1 is="marp-h1" data-auto-scaling id="loading-a-package">Loading a package</h1>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 960 720"><foreignObject width="960" height="720"><section id="11" data-class="invert" data-background-color="black" data-background-image="linear-gradient(to bottom, red, black)" data-theme="default" lang="en-US" class="invert" style="--class:invert;--background-color:black;--background-image:linear-gradient(to bottom, red, black);--theme:default;background-color:black;background-image:linear-gradient(to bottom, red, black);background-position:center;background-repeat:no-repeat;background-size:cover;" data-size="4:3">
<h1 is="marp-h1" data-auto-scaling id="be-friendly-to-others">Be friendly to others!</h1>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 960 720"><foreignObject width="960" height="720"><section id="12" data-class="invert" data-background-color="black" data-theme="default" lang="en-US" class="invert" style="--class:invert;--background-color:black;--theme:default;background-color:black;background-image:none;" data-size="4:3">
<h1 is="marp-h1" data-auto-scaling id="when-distributing-your-code-think-of-those-using-it">When distributing your code, think of those using it</h1>
<p>If you are using a slightly unusual library, it is possible that a person you share your code with does not have that library installed</p>
<p>In this case, it is nice to them if you spare them having to do the work to install the library</p>
<p>But it is also possible that they already have the library</p>
<p>In this case, it will be annoying to them if you trigger an installation of the library (especially under linux, since there libraries are compiled for installation)</p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 960 720"><foreignObject width="960" height="720"><section id="7" data-class="invert" data-background-color="black" data-theme="default" lang="en-US" class="invert" style="--class:invert;--background-color:black;--theme:default;background-color:black;background-image:none;" data-size="4:3">
<p>So the way to proceed is to test whether the library is installed</p>
<p>If it is, load it</p>
<p>If it is not, install it then load it</p>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 960 720"><foreignObject width="960" height="720"><section id="13" data-class="invert" data-background-color="black" data-theme="default" lang="en-US" class="invert" style="--class:invert;--background-color:black;--theme:default;background-color:black;background-image:none;" data-size="4:3">
<p>So the way to proceed is to <strong>test</strong> whether the library is installed</p>
<ul>
<li>If it is, load it</li>
<li>If it is not, install it then load it</li>
</ul>
<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-R"><span class="hljs-keyword">if</span> <span class="hljs-punctuation">(</span><span class="hljs-operator">!</span>require<span class="hljs-punctuation">(</span>package_name<span class="hljs-punctuation">)</span><span class="hljs-punctuation">)</span> <span class="hljs-punctuation">{</span>
install.packages<span class="hljs-punctuation">(</span><span class="hljs-string">&quot;package_name&quot;</span><span class="hljs-punctuation">)</span>
library<span class="hljs-punctuation">(</span>package_name<span class="hljs-punctuation">)</span>
<span class="hljs-punctuation">}</span>
</code></pre>
<blockquote>
<p><code>require</code> is designed for use inside other functions; it returns <code>FALSE</code> and gives a warning (rather than an error as <code>library()</code> does by default) if the package does not exist.</p>
</blockquote>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 960 720"><foreignObject width="960" height="720"><section id="14" data-class="invert" data-background-color="black" data-background-image="linear-gradient(to bottom, red, black)" data-theme="default" lang="en-US" class="invert" style="--class:invert;--background-color:black;--background-image:linear-gradient(to bottom, red, black);--theme:default;background-color:black;background-image:linear-gradient(to bottom, red, black);background-position:center;background-repeat:no-repeat;background-size:cover;" data-size="4:3">
<h1 is="marp-h1" data-auto-scaling id="updating-packages">Updating packages</h1>
</section>
<script>!function(){"use strict";const t={h1:{proto:()=>HTMLHeadingElement,attrs:{role:"heading","aria-level":"1"},style:"display: block; font-size: 2em; margin-block-start: 0.67em; margin-block-end: 0.67em; margin-inline-start: 0px; margin-inline-end: 0px; font-weight: bold;"},h2:{proto:()=>HTMLHeadingElement,attrs:{role:"heading","aria-level":"2"},style:"display: block; font-size: 1.5em; margin-block-start: 0.83em; margin-block-end: 0.83em; margin-inline-start: 0px; margin-inline-end: 0px; font-weight: bold;"},h3:{proto:()=>HTMLHeadingElement,attrs:{role:"heading","aria-level":"3"},style:"display: block; font-size: 1.17em; margin-block-start: 1em; margin-block-end: 1em; margin-inline-start: 0px; margin-inline-end: 0px; font-weight: bold;"},h4:{proto:()=>HTMLHeadingElement,attrs:{role:"heading","aria-level":"4"},style:"display: block; margin-block-start: 1.33em; margin-block-end: 1.33em; margin-inline-start: 0px; margin-inline-end: 0px; font-weight: bold;"},h5:{proto:()=>HTMLHeadingElement,attrs:{role:"heading","aria-level":"5"},style:"display: block; font-size: 0.83em; margin-block-start: 1.67em; margin-block-end: 1.67em; margin-inline-start: 0px; margin-inline-end: 0px; font-weight: bold;"},h6:{proto:()=>HTMLHeadingElement,attrs:{role:"heading","aria-level":"6"},style:"display: block; font-size: 0.67em; margin-block-start: 2.33em; margin-block-end: 2.33em; margin-inline-start: 0px; margin-inline-end: 0px; font-weight: bold;"},span:{proto:()=>HTMLSpanElement},pre:{proto:()=>HTMLElement,style:"display: block; font-family: monospace; white-space: pre; margin: 1em 0; --marp-auto-scaling-white-space: pre;"}},e="data-marp-auto-scaling-wrapper",i="data-marp-auto-scaling-svg",n="data-marp-auto-scaling-container";class s extends HTMLElement{constructor(){super(),this.svgPreserveAspectRatio="xMinYMid meet";const t=t=>([e])=>{const{width:i,height:n}=e.contentRect;this[t]={width:i,height:n},this.updateSVGRect()};this.attachShadow({mode:"open"}),this.containerObserver=new ResizeObserver(t("containerSize")),this.wrapperObserver=new ResizeObserver(((...e)=>{t("wrapperSize")(...e),this.flushSvgDisplay()}))}static get observedAttributes(){return["data-downscale-only"]}connectedCallback(){var t,s,o,r,a;this.shadowRoot.innerHTML=`\n<style>\n svg[${i}] { display: block; width: 100%; height: auto; vertical-align: top; }\n span[${n}] { display: table; white-space: var(--marp-auto-scaling-white-space, nowrap); width: max-content; }\n</style>\n<div ${e}>\n <svg part="svg" ${i}>\n <foreignObject><span ${n}><slot></slot></span></foreignObject>\n </svg>\n</div>\n `.split(/\n\s*/).join(""),this.wrapper=null!==(t=this.shadowRoot.querySelector(`div[${e}]`))&&void 0!==t?t:void 0;const l=this.svg;this.svg=null!==(o=null===(s=this.wrapper)||void 0===s?void 0:s.querySelector(`svg[${i}]`))&&void 0!==o?o:void 0,this.svg!==l&&(this.svgComputedStyle=this.svg?window.getComputedStyle(this.svg):void 0),this.container=null!==(a=null===(r=this.svg)||void 0===r?void 0:r.querySelector(`span[${n}]`))&&void 0!==a?a:void 0,this.observe()}disconnectedCallback(){this.svg=void 0,this.svgComputedStyle=void 0,this.wrapper=void 0,this.container=void 0,this.observe()}attributeChangedCallback(){this.observe()}flushSvgDisplay(){const{svg:t}=this;t&&(t.style.display="inline",requestAnimationFrame((()=>{t.style.display=""})))}observe(){this.containerObserver.disconnect(),this.wrapperObserver.disconnect(),this.wrapper&&this.wrapperObserver.observe(this.wrapper),this.container&&this.containerObserver.observe(this.container),this.svgComputedStyle&&this.observeSVGStyle(this.svgComputedStyle)}observeSVGStyle(t){const e=()=>{const i=(()=>{const e=t.getPropertyValue("--preserve-aspect-ratio");if(e)return e.trim();return`x${(({textAlign:t,direction:e})=>{if(t.endsWith("left"))return"Min";if(t.endsWith("right"))return"Max";if("start"===t||"end"===t){let i="rtl"===e;return"end"===t&&(i=!i),i?"Max":"Min"}return"Mid"})(t)}YMid meet`})();i!==this.svgPreserveAspectRatio&&(this.svgPreserveAspectRatio=i,this.updateSVGRect()),t===this.svgComputedStyle&&requestAnimationFrame(e)};e()}updateSVGRect(){var t,e,i,n,s,o,r;let a=Math.ceil(null!==(e=null===(t=this.containerSize)||void 0===t?void 0:t.width)&&void 0!==e?e:0);const l=Math.ceil(null!==(n=null===(i=this.containerSize)||void 0===i?void 0:i.height)&&void 0!==n?n:0);void 0!==this.dataset.downscaleOnly&&(a=Math.max(a,null!==(o=null===(s=this.wrapperSize)||void 0===s?void 0:s.width)&&void 0!==o?o:0));const c=null===(r=this.svg)||void 0===r?void 0:r.querySelector(":scope > foreignObject");if(null==c||c.setAttribute("width",`${a}`),null==c||c.setAttribute("height",`${l}`),this.svg&&(this.svg.setAttribute("viewBox",`0 0 ${a} ${l}`),this.svg.setAttribute("preserveAspectRatio",this.svgPreserveAspectRatio),this.svg.style.height=a<=0||l<=0?"0":""),this.container){const t=this.svgPreserveAspectRatio.toLowerCase();this.container.style.marginLeft=t.startsWith("xmid")||t.startsWith("xmax")?"auto":"0",this.container.style.marginRight=t.startsWith("xmi")?"auto":"0"}}}const o=(t,{attrs:e={},style:i})=>class extends t{constructor(...t){super(...t);for(const[t,i]of Object.entries(e))this.hasAttribute(t)||this.setAttribute(t,i);this.attachShadow({mode:"open"})}static get observedAttributes(){return["data-auto-scaling"]}connectedCallback(){this._update()}attributeChangedCallback(){this._update()}_update(){const t=i?`<style>:host { ${i} }</style>`:"";let e="<slot></slot>";const{autoScaling:n}=this.dataset;if(void 0!==n){e=`<marp-auto-scaling exportparts="svg:auto-scaling" ${"downscale-only"===n?"data-downscale-only":""}>${e}</marp-auto-scaling>`}this.shadowRoot.innerHTML=t+e}};let r;const a=Symbol();let l;const c="marpitSVGPolyfill:setZoomFactor,",d=Symbol(),g=Symbol();const h=()=>{const t="Apple Computer, Inc."===navigator.vendor,e=t?[u]:[],i={then:e=>(t?(async()=>{if(void 0===l){const t=document.createElement("canvas");t.width=10,t.height=10;const e=t.getContext("2d"),i=new Image(10,10),n=new Promise((t=>{i.addEventListener("load",(()=>t()))}));i.crossOrigin="anonymous",i.src="data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2210%22%20height%3D%2210%22%20viewBox%3D%220%200%201%201%22%3E%3CforeignObject%20width%3D%221%22%20height%3D%221%22%20requiredExtensions%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cdiv%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%20style%3D%22width%3A%201px%3B%20height%3A%201px%3B%20background%3A%20red%3B%20position%3A%20relative%22%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fsvg%3E",await n,e.drawImage(i,0,0),l=e.getImageData(5,5,1,1).data[3]<128}return l})().then((t=>{null==e||e(t?[u]:[])})):null==e||e([]),i)};return Object.assign(e,i)};let p,m;function u(t){const e="object"==typeof t&&t.target||document,i="object"==typeof t?t.zoom:t;window[g]||(Object.defineProperty(window,g,{configurable:!0,value:!0}),document.body.style.zoom=1.0001,document.body.offsetHeight,document.body.style.zoom=1,window.addEventListener("message",(({data:t,origin:e})=>{if(e===window.origin)try{if(t&&"string"==typeof t&&t.startsWith(c)){const[,e]=t.split(","),i=Number.parseFloat(e);Number.isNaN(i)||(m=i)}}catch(t){console.error(t)}})));let n=!1;Array.from(e.querySelectorAll("svg[data-marpit-svg]"),(t=>{var e,s,o,r;t.style.transform||(t.style.transform="translateZ(0)");const a=i||m||t.currentScale||1;p!==a&&(p=a,n=a);const l=t.getBoundingClientRect(),{length:c}=t.children;for(let i=0;i<c;i+=1){const n=t.children[i];if(n.getScreenCTM){const t=n.getScreenCTM();if(t){const i=null!==(s=null===(e=n.x)||void 0===e?void 0:e.baseVal.value)&&void 0!==s?s:0,c=null!==(r=null===(o=n.y)||void 0===o?void 0:o.baseVal.value)&&void 0!==r?r:0,d=n.children.length;for(let e=0;e<d;e+=1){const s=n.children[e];if("SECTION"===s.tagName){const{style:e}=s;e.transformOrigin||(e.transformOrigin=`${-i}px ${-c}px`),e.transform=`scale(${a}) matrix(${t.a}, ${t.b}, ${t.c}, ${t.d}, ${t.e-l.left}, ${t.f-l.top}) translateZ(0.0001px)`;break}}}}}})),!1!==n&&Array.from(e.querySelectorAll("iframe"),(({contentWindow:t})=>{null==t||t.postMessage(`${c}${n}`,"null"===window.origin?"*":window.origin)}))}function v({once:t=!1,target:e=document}={}){const i=function(t=document){if(t[d])return t[d];let e=!0;const i=()=>{e=!1,delete t[d]};Object.defineProperty(t,d,{configurable:!0,value:i});let n=[],s=!1;(async()=>{try{n=await h()}finally{s=!0}})();const o=()=>{for(const e of n)e({target:t});s&&0===n.length||e&&window.requestAnimationFrame(o)};return o(),i}(e);return t?(i(),()=>{}):i}p=1,m=void 0;const b=Symbol(),w=(e=document)=>{if("undefined"==typeof window)throw new Error("Marp Core's browser script is valid only in browser context.");if(((e=document)=>{const i=window[a];i||customElements.define("marp-auto-scaling",s);for(const n of Object.keys(t)){const s=`marp-${n}`,a=t[n].proto();null!=r||(r=!!document.createElement("div",{is:"marp-auto-scaling"}).outerHTML.startsWith("<div is")),r&&a!==HTMLElement?i||customElements.define(s,o(a,{style:t[n].style}),{extends:n}):(i||customElements.define(s,o(HTMLElement,t[n])),e.querySelectorAll(`${n}[is="${s}"]`).forEach((t=>{t.outerHTML=t.outerHTML.replace(new RegExp(`^<${n}`,"i"),`<${s}`).replace(new RegExp(`</${n}>$`,"i"),`</${s}>`)})))}window[a]=!0})(e),e[b])return e[b];const i=v({target:e}),n=()=>{i(),delete e[b]},l=Object.assign(n,{cleanup:n,update:()=>w(e)});return Object.defineProperty(e,b,{configurable:!0,value:l}),l},y=document.currentScript;w(y?y.getRootNode():document)}();
</script></foreignObject></svg></div><script>/*!! License: https://unpkg.com/@marp-team/marp-cli@3.4.0/lib/bespoke.js.LICENSE.txt */
Expand Down
Loading

0 comments on commit b4772e2

Please sign in to comment.