TikTok in R?!?!

Late last week, Garrick Aden-Buie announced a new package that allow us to embed TikTok videos into R Markdown files. The package is called tiktokrmd and can be found here. It should also be noted that Garrick, has a number of other fun samples and packages on his website, that I highly encourage y’all to check out.

Install the Package

Installing the package is straight forward through the install_github() function in the remotes package. This happened to be the first new package I downloaded from GitHub on a repo that was created since the default branch was named main, so I encountered the need to employ one of two techniques below.

  1. You can just update the remotes package as Garrick pointed out.

  2. You can specify the branch as @main as I mentioned in a tweet.

#1) Update remotes to find the default branch
#install.packages("remotes")
#library(remotes)
#remotes::install_github("gadenbuie/tiktokrmd")

#2) Or if you have the remotes package installed and don't want to or can't re-install, you can just specify the branch
#remotes::install_github("gadenbuie/tiktokrmd@main")
library(tiktokrmd)

Embed your favorite TikTok video

This is probably the easiest tutorial I’ve written, just because of how simple Garrick has made his package. As per the instructions on his GitHub repo, simply set a variable to the TikTok video URL, pass it through the tiktok_embed function, and then pass that through the tiktok_html function.

For my example, I am including my favorite data TikTok by Chelsea Parlett. I highly encourage y’all to check out her videos!

tt_url <- "https://www.tiktok.com/@chelseaparlettpelleriti/video/6811647290709757189"
tt <- tiktok_embed(tt_url)

Display the video

tt
@chelseaparlettpelleriti

Always check your assumptions 📈#statistics #math #linearregression #fyp

♬ is it me, Jesus? - Mackenzie Lee

Display the plain markdown

tiktok_md(tt)
## [1] "![[Always check your assumptions \U0001f4c8#statistics #math #linearregression #fyp](https://www.tiktok.com/@chelseaparlettpelleriti/video/6811647290709757189) by [Chelsea Parlett](https://www.tiktok.com/@chelseaparlettpelleriti)](https://p16-sign-va.tiktokcdn.com/obj/tos-maliva-p-0068/bf5936b466034bac802ded847bb21da5_1585960232?x-expires=1611007200&x-signature=GznludgV9kv%2Btpb2JDKQZY55N5k%3D)"

Knit to HTML and host online

In the repo, Garrick points out that the html file needs to be hosted somewhere to fully display the video. Luckily GitHub pages has us covered.

Just follow the steps in my previous blog here to host your html, .Rmd output on GitHub pages.

Thank You

Thank you for following along and good luck with trying out the package!

<3 Littlemissdata