Custom snippets in RStudio: ⚡ faster tweet chunks for all

✂️ Snippets in RStudio

As Sean Lopp describes in his super helpful post, RStudio IDE Easy Tricks You Might’ve Missed ⭐:

Code snippets are a shortcut to insert common boilerplate code.

You might also refer to them as “text macros”1— either way, they’re useful for speeding up the process of doing a thing in RStudio that you do frequently. In my case, this includes inserting “tweet chunks” in blogdown posts using a Hugo shortcode.2

📝 Adding a Markdown snippet

The RStudio Support Code Snippets post is a great step-by-step for adding snippets of your own. The gist of it for a markdown snippet is as follows:

  1. Open RStudio Preferences
  2. Go to the Code section
  3. Click the Edit Snippets button3
  4. Select Markdown
  5. Add your snippet and Save 🎉

🐦 twe blogdown snippet

Now, for the actual snippet, and how to use it.

1. Get the tweet id number from twitter 🐦

2. Go into your R Markdown document

3. Type t-w-e and then ⌨️ Shift-Tab

4. Fill in tweetid (paste if copied)

5. Serve site 🎉

Fin

Go forth, embed tweets, and prosper! Hit me up @dataandme, or comment if I got something wrong, or right, or if the spirit moves you to do so. 💖


  1. As does J.J. Allaire in the useful Code Snippets entry of RStudio Support.

  2. For more examples of using shortcodes in blogdown, check out Andrew Clark’s handy Hugo Shortcodes post.

  3. If the Enable code snippets radio button isn’t checked, click that, too.

Share Comments
comments powered by Disqus