<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>snippet | Thought splinters</title>
    <link>https://notes.peter-baumgartner.net/tag/snippet/</link>
      <atom:link href="https://notes.peter-baumgartner.net/tag/snippet/index.xml" rel="self" type="application/rss+xml" />
    <description>snippet</description>
    <generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><copyright>CC BY-SA 4.0</copyright><lastBuildDate>Wed, 12 Jun 2019 00:00:00 +0000</lastBuildDate>
    <image>
      <url>https://notes.peter-baumgartner.net/media/icon_huab1e86cf5cbc1139acf672dc60b9d7d0_5213_512x512_fill_lanczos_center_2.png</url>
      <title>snippet</title>
      <link>https://notes.peter-baumgartner.net/tag/snippet/</link>
    </image>
    
    <item>
      <title>RStudio Snippets for Markdown</title>
      <link>https://notes.peter-baumgartner.net/2019/06/12/rstudio-snippets-for-markdown/</link>
      <pubDate>Wed, 12 Jun 2019 00:00:00 +0000</pubDate>
      <guid>https://notes.peter-baumgartner.net/2019/06/12/rstudio-snippets-for-markdown/</guid>
      <description>


&lt;h2 id=&#34;tutorial-for-rstudio-code-snippets&#34;&gt;Tutorial for RStudio code snippets&lt;a href=&#34;#tutorial-for-rstudio-code-snippets&#34;&gt;&lt;svg class=&#34;anchor-symbol&#34; height=&#34;26&#34; width=&#34;26&#34; viewBox=&#34;0 0 22 22&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;
&lt;path d=&#34;M0 0h24v24H0z&#34; fill=&#34;currentColor&#34;&gt;&lt;/path&gt;
&lt;path d=&#34;M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z&#34;&gt;&lt;/path&gt;
&lt;/svg&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Code snippets are text macros which you can insert into your programs. They are used for repetitive tasks and can boost your productivity tremendously. Here I am not going to explain how to use it. There are already several good tutorials around:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The official &lt;a href=&#34;https://support.rstudio.com/hc/en-us/articles/204463668-Code-Snippets&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;RStudio tutorial&lt;/a&gt; on code snippets&lt;/li&gt;
&lt;li&gt;A &lt;a href=&#34;https://datacritics.com/2019/01/28/rstudio-snippets/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Blog entry by Jake Daniels&lt;/a&gt;: How RStudio Snippets Improve My Productivity&lt;/li&gt;
&lt;li&gt;A &lt;a href=&#34;https://jozef.io/r906-rstudio-snippets/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Blog entry by Jozef Hajnala&lt;/a&gt;: 4 ways to be more efficient using RStudio&amp;rsquo;s Code Snippets, with 11 ready to use examples&lt;/li&gt;
&lt;li&gt;A &lt;a href=&#34;https://www.youtube.com/watch?v=h_i__VTSurU&amp;amp;list=PL7D2RMSmRO9JOvPC1gbA8Mc3azvSfm8Vv&amp;amp;index=28&amp;amp;t=141s&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Video by Sharon Machlis&lt;/a&gt;: R tip: Save time with RStudio code snippets (part of her video channel &lt;a href=&#34;https://www.youtube.com/playlist?list=PL7D2RMSmRO9JOvPC1gbA8Mc3azvSfm8Vv&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Do more with R&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;



&lt;h2 id=&#34;eight-useful-reminders&#34;&gt;Eight useful reminders&lt;a href=&#34;#eight-useful-reminders&#34;&gt;&lt;svg class=&#34;anchor-symbol&#34; height=&#34;26&#34; width=&#34;26&#34; viewBox=&#34;0 0 22 22&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;
&lt;path d=&#34;M0 0h24v24H0z&#34; fill=&#34;currentColor&#34;&gt;&lt;/path&gt;
&lt;path d=&#34;M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z&#34;&gt;&lt;/path&gt;
&lt;/svg&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;In this post, I want to summarize some important details, which I learned laboriously after time-consuming trials:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The Markdown section in the snippet editor works only with &lt;code&gt;.Rmd&lt;/code&gt; and &lt;code&gt;.Rmarkdown&lt;/code&gt; files. &amp;ndash; So if you are going to write just text (e.g., a blog entry) &lt;em&gt;and&lt;/em&gt; you want use RStudio snippets to insert shortcodes than you have to write into &lt;code&gt;.Rmd&lt;/code&gt; / &lt;code&gt;.Rmarkdown&lt;/code&gt; files.&lt;/li&gt;
&lt;li&gt;The snippets in the R section of the snippet editor are for code chunks whereas the snippets in the Markdown section work only in markdown text of &lt;code&gt;.Rmd&lt;/code&gt; / &lt;code&gt;.Rmarkdown&lt;/code&gt; files.&lt;/li&gt;
&lt;li&gt;To insert snippets in the Markdown part of &lt;code&gt;.Rmd&lt;/code&gt; / &lt;code&gt;.Rmarkdown&lt;/code&gt; files, you have to use SHIFT-TAB (and not just TAB as for R snippets in the code chunks).&lt;/li&gt;
&lt;li&gt;To write your snippets, you have to use the TAB key for indenting. 4 Spaces do not work!&lt;/li&gt;
&lt;li&gt;It is legitimate to write huge snippets for large code junks. For instance, you can write complex &lt;code&gt;ggplot2&lt;/code&gt; snippets as a kind of a template you are going to use frequently.&lt;/li&gt;
&lt;li&gt;For large code chunks, it may be preferable to write the snippets with the RStudio code pane. You can load the snippet files under &lt;code&gt;~/.R/r.snippets&lt;/code&gt; respectively ~&lt;code&gt;.R/markdown.snippets&lt;/code&gt; into RStudio.&lt;/li&gt;
&lt;li&gt;You can share you snippets sending these files to your colleagues and collaborators.&lt;/li&gt;
&lt;li&gt;Do not use names, which are difficult to type to call your snippets. For instance, to insert the markdown syntax for an image do not name it &amp;ldquo;![&amp;rdquo; but &amp;ldquo;ii&amp;rdquo; for example.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;span class=&#39;Z3988&#39; title=&#39;url_ver=Z39.88-2004&amp;amp;ctx_ver=Z39.88-2004&amp;amp;rfr_id=info%3Asid%2Fzotero.org%3A2&amp;amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&amp;amp;rft.type=blogPost&amp;amp;rft.title=RStudio%20Snippets%20for%20Markdown%20%3A%3A%20Open%20Science%20Education&amp;amp;rft.source=RStudio%20Snippets%20for%20Markdown&amp;amp;rft.rights=CC%20BY-SA%204.0&amp;amp;rft.description=Code%20snippets%20are%20text%20macros%20which%20you%20can%20insert%20into%20your%20programs.%20They%20are%20used%20for%20repetitive%20tasks%20and%20can%20boost%20your%20productivity%20tremendously.%20After%20providing%20some%20link%20to%20tutorials%20about%20RStudio%20snippets%2C%20I%20am%20going%20to%20summarize%20eight%20reminders%20for%20practical%20usage.&amp;amp;rft.identifier=https%3A%2F%2Fnotes.peter-baumgartner.net%2F2019%2F06%2F12%2Frstudio-snippets-for-markdown%2F&amp;amp;rft.aufirst=Peter&amp;amp;rft.aulast=Baumgartner&amp;amp;rft.au=Peter%20Baumgartner&amp;amp;rft.date=2019-06-07&amp;amp;rft.language=EN&#39;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&#39;Z3988&#39; title=&#39;url_ver=Z39.88-2004&amp;amp;ctx_ver=Z39.88-2004&amp;amp;rfr_id=info%3Asid%2Fzotero.org%3A2&amp;amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&amp;amp;rft.type=blogPost&amp;amp;rft.title=RStudio%20Snippets%20for%20Markdown%20::%20Open%20Science%20Education&amp;amp;rft.source=RStudio%20Snippets%20for%20Markdown&amp;amp;rft.rights=CC%20BY-SA%204.0&amp;amp;rft.description=Code%20snippets%20are%20text%20macros%20which%20you%20can%20insert%20into%20your%20programs.%20They%20are%20used%20for%20repetitive%20tasks%20and%20can%20boost%20your%20productivity%20tremendously.%20After%20providing%20some%20link%20to%20tutorials%20about%20RStudio%20snippets,%20I%20am%20going%20to%20summarize%20eight%20reminders%20for%20practical%20usage.&amp;amp;rft.identifier=https%3A%2F%2Fnotes.peter-baumgartner.net%2F2019%2F06%2F12%2Frstudio-snippets-for-markdown&amp;amp;rft.aufirst=Peter&amp;amp;rft.aulast=Baumgartner&amp;amp;rft.au=Peter%20Baumgartner&amp;amp;rft.date=&amp;amp;rft.language=en&#39;&gt;&lt;/span&gt;&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>
