Giter Club home page Giter Club logo

tweetrmd's Introduction

tweetrmd

Easily embed Tweets anywhere R Markdown turns plain text into HTML.

Installation

You can install the released version of tweetrmd from GitHub:

# install.packages("devtools")
devtools::install_github("gadenbuie/tweetrmd")

Embed a Tweet

library(tweetrmd)
tweet_embed("https://twitter.com/alexpghayes/status/1211748406730706944")

anybody have experience embedding tweets into #rmarkdown documents without using blogdown?https://t.co/5kQUBh7j4g

— alex hayes (@alexpghayes) December 30, 2019

Or if you would rather use the screen name and status id.

tweet_embed(tweet_url("alexpghayes", "1211748406730706944"))

anybody have experience embedding tweets into #rmarkdown documents without using blogdown?https://t.co/5kQUBh7j4g

— alex hayes (@alexpghayes) December 30, 2019

In rich HTML outputs, the full embedded tweet is available and interactive. Here, in GitHub-flavored markdown, only the content of the tweet is seen.

Take a screenshot of a tweet

Screenshots are automatically embedded in R Markdown documents, or you can save the screenshot as a .png or .pdf file. Uses the rstudio/webshot2 package.

tweet_screenshot(tweet_url("alexpghayes", "1211748406730706944"))

Customize tweet appearance

Twitter’s oembed API provides a number of options, all of which are made available for customization in tweet_embed() and tweet_screenshot().

tweet_screenshot(
  tweet_url("alexpghayes", "1211748406730706944"),
  maxwidth = 300,
  hide_media = TRUE,
  theme = "dark"
)

Caching tweets with memoization

Tweets are often deleted and re-running tweet_embed() or tweet_screenshot() may fail or overwrite a previous screenshot of a tweet. To avoid this, you can use the memoise package.

library(memoise)

tweet_cached <- memoise(tweet_embed, cache = cache_filesystem('.tweets'))
tweet_shot_cached <- memoise(tweet_screenshot, cache = cache_filesystem('.tweets'))

*When memoising tweet_screenshot() you need to manually save the file to a specific location. In the future my goal is for this to be automatic.


Note: When using tweet_embed(), you may need to add the following line to your YAML header for strict markdown output formats.

always_allow_html: true

tweetrmd's People

Contributors

gadenbuie avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.