---
title: "Basic Usage"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Basic_Usage}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
# Introduction
Welcome to the `atrrr` vignette! This guide will delve deeper into the functionalities offered by the package-
Before diving in, let's clarify some terminology. In the context of Blue Sky, a post is referred to as a "skeet." So, when we mention retrieving or working with "skeets," we are talking about individual posts made on Blue Sky.
Now, let's delve deeper into the functionalities that allow users to interact with skeets, followers, and their descriptions.
## Installation
If you haven't done so, you can install the development version of atrrr like so (`pak` works similar to `remotes` here, but it's what the cool kids use now :grin:):
``` r
# install.packages("pak")
pak::pak("JBGruber/atrrr")
```
## Load the package
``` r
library(atrrr)
```
## Authentication
The first time you make a request, you will be prompted automatically to enter your user handle and an app password to authenticate `atrrr` to communicate with BlueSky for you.
![RStudio Popup](figures/password_popup.png)
The page to generate app passwords is also automatically opened for you.
![page to create new app passwords](figures/app_password.png)
However, you can also trigger this process manually:
``` r
auth("jbgruber.bsky.social")
```
This can be useful if you want to replace an old token as it is permanently stored encrypted on disk.
# Searching Posts
You can search Posts on Bluesky using a small set of operators:
- Whitespace is treated as implicit AND, so all words in a query must occur
- Double quotes indicate exact phrases
- `from:` will filter to results from that account
- `-` excludes terms
Note that matches can occur anywhere in the skeet, not just the text.
For example, a term can be in the link preview, or alt text of an image.
A couple of examples:
``` r
search_post("rstats")
#> # A tibble: 100 × 18
#> uri cid author_handle author_name text author_data post_data embed_data reply_count
#>
#> 1 at:/… bafy… tterence.bsk… terence "Lig… 0
#> 2 at:/… bafy… emazaola.bsk… "Mor… 0
#> 3 at:/… bafy… rosenetwork.… RoSE Netwo… "🚨N… 0
#> 4 at:/… bafy… cranberriesf… CRAN Packa… "CRA… 0
#> 5 at:/… bafy… avehtari.bsk… Aki Vehtar… "The… 1
#> 6 at:/… bafy… cranberriesf… CRAN Packa… "CRA… 0
#> 7 at:/… bafy… jimjamslam.b… James Gold… "💡 … 0
#> 8 at:/… bafy… tterence.bsk… terence "Riv… 1
#> 9 at:/… bafy… jeremywallac… Jeremy Wal… "Wel… 0
#> 10 at:/… bafy… cranberriesf… CRAN Packa… "CRA… 0
#> # ℹ 90 more rows
#> # ℹ 9 more variables: repost_count , like_count , indexed_at ,
#> # in_reply_to , in_reply_root , quotes , tags , mentions ,
#> # links
```
This finds posts where "rstats" is found somewhere in the post.
``` r
search_post("#rstats Bluesky")
#> # A tibble: 34 × 18
#> uri cid author_handle author_name text author_data post_data embed_data reply_count
#>
#> 1 at:/… bafy… gdeejay.bsky… Giles "One… 0
#> 2 at:/… bafy… dariia.bsky.… Dariia Myk… "Blu… 0
#> 3 at:/… bafy… o.simardcasa… Olivier Si… "Thi… 16
#> 4 at:/… bafy… thomascwells… Thomas W "Jus… 0
#> 5 at:/… bafy… nrennie.bsky… Nicola Ren… "A r… 0
#> 6 at:/… bafy… o.simardcasa… Olivier Si… "The… 0
#> 7 at:/… bafy… thoughtfulnz… David Hood "Che… 1
#> 8 at:/… bafy… o.simardcasa… Olivier Si… "Wit… 2
#> 9 at:/… bafy… seacatkim.bs… Catherine "Hel… 4
#> 10 at:/… bafy… thoughtfulnz… David Hood "#30… 2
#> # ℹ 24 more rows
#> # ℹ 9 more variables: repost_count , like_count , indexed_at ,
#> # in_reply_to , in_reply_root , quotes , tags , mentions ,
#> # links
```
This finds posts with the hashtag "rstats" AND the word Bluesky somewhere in the skeet (ignoring capitalisaion).
You can also search for the exact phrase "new #rstats package":
``` r
search_post("\"new #rstats package\"")
#> # A tibble: 17 × 18
#> uri cid author_handle author_name text author_data post_data embed_data reply_count
#>
#> 1 at:/… bafy… seabbs.bsky.… "Sam Abbot… "New… 1
#> 2 at:/… bafy… coatless.bsk… "James Bal… "Int… 0
#> 3 at:/… bafy… heinersalomo… "Heiner Sa… "Thi… 1
#> 4 at:/… bafy… egorkotov.bs… "Egor Koto… "We'… 0
#> 5 at:/… bafy… egorkotov.bs… "Egor Koto… "Fai… 0
#> 6 at:/… bafy… frodsan.bsky… "Francisco… "Thi… 1
#> 7 at:/… bafy… simonpcouch.… "Simon P. … "🚨N… 0
#> 8 at:/… bafy… posit.co "Posit" "We’… 0
#> 9 at:/… bafy… chriskenny.b… "Chris Ken… "New… 0
#> 10 at:/… bafy… robjhyndman.… "Rob Hyndm… "My … 0
#> 11 at:/… bafy… cghlewis.bsk… "Crystal L… "Whe… 0
#> 12 at:/… bafy… jbgruber.bsk… "Johannes … "New… 1
#> 13 at:/… bafy… mikemahoney2… "Mike Maho… "📣 … 0
#> 14 at:/… bafy… mikemahoney2… "Mike Maho… "Exc… 0
#> 15 at:/… bafy… jbgruber.bsk… "Johannes … "New… 1
#> 16 at:/… bafy… pciarchaeolo… "" "2/3… 1
#> 17 at:/… bafy… eddelbuettel… "Dirk Edde… "Eve… 0
#> # ℹ 9 more variables: repost_count , like_count , indexed_at ,
#> # in_reply_to , in_reply_root , quotes , tags , mentions ,
#> # links
```
``` r
#' # Use single quotes so you do not need to escape double quotes
#' search_post('"new #rstats package"')
```
You can also limit your search by only looking for skeets from one user:
``` r
search_post("from:jbgruber.bsky.social #rstats")
#> # A tibble: 31 × 18
#> uri cid author_handle author_name text author_data post_data embed_data reply_count
#>
#> 1 at:/… bafy… jbgruber.bsk… Johannes B… "Tes… 0
#> 2 at:/… bafy… jbgruber.bsk… Johannes B… "Tes… 0
#> 3 at:/… bafy… jbgruber.bsk… Johannes B… "Tes… 0
#> 4 at:/… bafy… jbgruber.bsk… Johannes B… "lla… 1
#> 5 at:/… bafy… jbgruber.bsk… Johannes B… "I t… 1
#> 6 at:/… bafy… jbgruber.bsk… Johannes B… "I j… 1
#> 7 at:/… bafy… jbgruber.bsk… Johannes B… "I a… 1
#> 8 at:/… bafy… jbgruber.bsk… Johannes B… "Che… 1
#> 9 at:/… bafy… jbgruber.bsk… Johannes B… "For… 0
#> 10 at:/… bafy… jbgruber.bsk… Johannes B… "My … 0
#> # ℹ 21 more rows
#> # ℹ 9 more variables: repost_count , like_count , indexed_at ,
#> # in_reply_to , in_reply_root , quotes , tags , mentions ,
#> # links
```
# Blue Sky Users and Skeets
## Retrieve user info (`get_user_info`)
A good starting point is understanding a user's digital footprint on the platform. The get_user_info function becomes our handy tool, fetching an array of information about a user. All you need? Their handle!
``` r
get_user_info(actor = "atpr.bsky.social") |>
dplyr::glimpse()
#> Rows: 1
#> Columns: 8
#> $ did "did:plc:j42kj4qc5vfz344weywpkair"
#> $ indexed_at 1-01-01
#> $ actor_handle "atpr.bsky.social"
#> $ actor_name NA
#> $ actor_description NA
#> $ actor_avatar NA
#> $ viewer_data [FALSE, FALSE, "at://did:plc:ntd53albt5ffa4rgervvgibd/app.bsky.graph.…
#> $ labels_data []
```
This function gives us counts of followers, follows, posts for each user.
You can also retrieve information for multiple users by providing a vector of user handles:
``` r
get_user_info(actor = c("benguinaudeau.bsky.social", "atpr.bsky.social")) |>
dplyr::glimpse()
#> Rows: 2
#> Columns: 8
#> $ did "did:plc:vuvsifrusnjsys7mhkpk662u", "did:plc:j42kj4qc5vfz344weywpkair"
#> $ indexed_at 2024-01-26 01:28:47, 1-01-01 00:00:00
#> $ actor_handle "benguinaudeau.bsky.social", "atpr.bsky.social"
#> $ actor_name "Benjamin Guinaudeau", NA
#> $ actor_description "Postdoc @CSMaP_NYU. \n\nPolitics, data science, and hacking stuff in…
#> $ actor_avatar "https://cdn.bsky.app/img/avatar/plain/did:plc:vuvsifrusnjsys7mhkpk6…
#> $ viewer_data [FALSE, FALSE, "at://did:plc:ntd53albt5ffa4rgervvgibd/app.bsky.graph.…
#> $ labels_data [], []
```
## Retrieve Skeets (`get_skeets_authored_by`)
To fetch all the skeets by a specific user, use the `get_skeets_authored_by` function. *Note this also includes quote skeets and reskeets.* You can also opt not to parse the result by setting `parse = FALSE`, however it is recommended to use the default parse option which results in a (more) tidy tibble.
``` r
get_skeets_authored_by(actor = "benguinaudeau.bsky.social", parse = TRUE) |>
dplyr::glimpse()
#> Rows: 25
#> Columns: 19
#> $ uri "at://did:plc:f5jstfwgvzacfsdjjdia4466/app.bsky.feed.post/3knyr4ydsqb2w",…
#> $ cid "bafyreieqiqwb4wwzosmx4jg3cee5ob2guc6qnjswkridxokkh23fm6wghq", "bafyreiab…
#> $ author_handle "jacobmontgomery.bsky.social", "beamagistro.bsky.social", "jbgruber.bsky.…
#> $ author_name "I jacob, the pumpkin king 🎃 👑 ", "Beatrice Magistro", "Johannes B. Gru…
#> $ text "Seriously? Not a single woman instructor, presenter, or organizer for a …
#> $ author_data ["did:plc:f5jstfwgvzacfsdjjdia4466", "jacobmontgomery.bsky.social", "I j…
#> $ post_data ["app.bsky.feed.post", "2024-03-18T21:09:28.158Z", ["app.bsky.embed.exte…
#> $ embed_data ["app.bsky.embed.external#view", ["https://www.law.northwestern.edu/rese…
#> $ reply_count 0, 0, 1, 4, 0, 0, 4, 0, 1, 9, 0, 1, 0, 1, 0, 0, 0, 0, 1, 12, 0, 0, 1, 1, 1
#> $ repost_count 3, 6, 6, 8, 0, 0, 15, 2, 1, 431, 3, 1, 5, 28, 0, 0, 0, 0, 0, 289, 14, 1, …
#> $ like_count 13, 12, 20, 13, 1, 1, 42, 6, 1, 609, 7, 3, 10, 35, 1, 0, 1, 3, 2, 453, 37…
#> $ indexed_at 2024-03-18 21:09:28, 2024-02-16 17:26:58, 2024-01-10 15:23:18, 2024-01-04…
#> $ in_reply_to NA, NA, NA, NA, NA, "at://did:plc:eotrvt2wp6mqooxjf3bzklwa/app.bsky.feed…
#> $ in_reply_root NA, NA, NA, NA, NA, "at://did:plc:eotrvt2wp6mqooxjf3bzklwa/app.bsky.feed.…
#> $ quotes NA, NA, "at://did:plc:vgvueqvmbqgoyxtcdebqdcgb/app.bsky.feed.post/3kin4vi…
#> $ tags , , "rstats", "rstats", , , , , "AoE"…
#> $ mentions