ale*_*yes 5 r r-markdown rtweet
使用 R 包和 Hugo 短代码将推文嵌入到博客文章中相当容易,如https://bookdown.org/yihui/blogdown/content.htmlblogdown中所述。
我想将推文嵌入到正在编织成独立 HTML 文档的 R markdown 文档中。做这个的最好方式是什么?看起来 Twitter 提供了嵌入推文功能,我可以交互地使用该功能来获取 HTML 来嵌入推文,但我需要在给定推文 ID 的情况下以编程方式执行此操作。
对于不想上 Twitter 的人,该线程包含两个软件包的推荐。twittrmd和twitterwidget。我能够twittrmd按如下方式开始工作:
这是最困难的部分,因为 CRANwebshot2存储库与我的 R 环境不兼容。
devtools::install_github("gadenbuie/tweetrmd")
# necessary if your output type is not html (as far as I can tell)
devtools::install_github("rstudio/webshot2")
# this is a webshot2 requirement
install.packages("magick")
Run Code Online (Sandbox Code Playgroud)
使用这些软件包,您可以通过以下方式捕获屏幕截图
library(twittrmd)
include_tweet("https://twitter.com/nomadj1s/status/1294390352904966151")
Run Code Online (Sandbox Code Playgroud)
如果您的输出类型不是 html,tweetrmd将呈现为 png 或 pdf。无论如何,我想你只能在编织时才能看到这条推文。
更多信息可在github上找到,包括根据用户名和 tweet_id 构建 twitter url 的辅助函数,以及如何在memoise推文从 Twitter 中删除时保留推文副本的想法。