Skip to content

application

chainsawriot edited this page Nov 28, 2022 · 4 revisions

The application column of the tibble returned from get_timeline_*, stream_timeline_*, or get_account_statuses is a list-column and it can be quite tricky to analyze.

The tricky part is that if a toot is a reblog then the application field is an empty list. We recommend tidying the field this way:

require(rtoot)
#> Loading required package: rtoot
require(purrr)
#> Loading required package: purrr

extract_application <- function(application) {
    if (length(application) == 0) {
        return(NA)
    } else {
        return(application$name)
    }
}

x <- get_account_statuses(id = "109337011845249544",
                          instance = "emacs.ch", limit = 20)
x
#> # A tibble: 20 × 29
#>    id          uri   created_at          content visib…¹ sensi…² spoil…³ reblo…⁴
#>    <chr>       <chr> <dttm>              <chr>   <chr>   <lgl>   <chr>     <int>
#>  1 1094223681… http… 2022-11-28 16:27:13 "<p>Th… public  FALSE   ""            0
#>  2 1094216017… http… 2022-11-28 13:12:19 "<p>Wh… public  FALSE   ""            0
#>  3 1094209516… http… 2022-11-28 10:27:00 "<p>Wh… public  TRUE    "Docke…       0
#>  4 1094208797… http… 2022-11-28 10:08:43 ""      public  FALSE   ""            0
#>  5 1094173460… http… 2022-11-27 19:10:03 "<p>Ca… public  TRUE    "anyco…       0
#>  6 1094161982… http… 2022-11-27 14:18:08 "<p>Wh… public  TRUE    "DOI"         1
#>  7 1094158212… http… 2022-11-27 12:42:16 "<p>Wh… public  TRUE    "Japan…       0
#>  8 1094154096… http… 2022-11-27 10:57:35 "<p><a… public  FALSE   ""            0
#>  9 1094153153… http… 2022-11-27 10:33:37 "<p>Wh… public  TRUE    "Guida…       0
#> 10 1094152134… http… 2022-11-27 10:07:41 "<p>Wh… public  TRUE    "YouTu…       0
#> 11 1094119444… http… 2022-11-26 20:16:21 "<p>Wh… public  TRUE    "no va…       0
#> 12 1094113214… http… 2022-11-26 17:37:55 "<p><a… public  FALSE   ""            0
#> 13 1094052995… http… 2022-11-25 16:06:28 "<p><s… public  FALSE   ""            0
#> 14 1094051082… http… 2022-11-25 15:17:49 "<p>I … public  FALSE   ""            0
#> 15 1094048834… http… 2022-11-25 14:20:39 "<p>Wh… public  TRUE    "my ha…       0
#> 16 1093994447… http… 2022-11-24 15:17:31 "<p>Ba… public  FALSE   ""            0
#> 17 1093982672… http… 2022-11-24 10:18:04 "<p>So… public  FALSE   ""            0
#> 18 1093939978… http… 2022-11-23 16:12:18 "<p>So… public  FALSE   ""            0
#> 19 1093931063… http… 2022-11-23 12:25:34 "<p>Wa… public  FALSE   ""            0
#> 20 1093923647… http… 2022-11-23 09:16:58 "<p><s… public  FALSE   ""            0
#> # … with 21 more variables: favourites_count <int>, replies_count <int>,
#> #   url <chr>, in_reply_to_id <chr>, in_reply_to_account_id <chr>,
#> #   language <chr>, text <lgl>, application <I<list>>, poll <I<list>>,
#> #   card <I<list>>, account <list>, reblog <I<list>>,
#> #   media_attachments <I<list>>, mentions <I<list>>, tags <I<list>>,
#> #   emojis <I<list>>, favourited <lgl>, reblogged <lgl>, muted <lgl>,
#> #   bookmarked <lgl>, pinned <lgl>, and abbreviated variable names …

## showing just 5
x$application[1:5]
#> [[1]]
#> [[1]]$name
#> [1] "Mastodon for iOS"
#> 
#> [[1]]$website
#> [1] "https://app.joinmastodon.org/ios"
#> 
#> 
#> [[2]]
#> [[2]]$name
#> [1] "Web"
#> 
#> [[2]]$website
#> NULL
#> 
#> 
#> [[3]]
#> [[3]]$name
#> [1] "Web"
#> 
#> [[3]]$website
#> NULL
#> 
#> 
#> [[4]]
#> list()
#> 
#> [[5]]
#> [[5]]$name
#> [1] "Web"
#> 
#> [[5]]$website
#> NULL

purrr::map_chr(x$application, extract_application)
#>  [1] "Mastodon for iOS" "Web"              "Web"              NA                
#>  [5] "Web"              "Web"              "Web"              "Web"             
#>  [9] "Web"              "Web"              "Web"              "Web"             
#> [13] "Mastodon for iOS" "Web"              "Web"              "Web"             
#> [17] "Web"              "Web"              "Web"              "Web"

Created on 2022-11-28 by the reprex package (v2.0.1)

A quick analysis like this can be done: Comparing the length of toots from iOS and Web.

require(tidyverse)
#> Loading required package: tidyverse

x %>% mutate(device = purrr::map_chr(x$application, extract_application), 
             toot_length = nchar(content)) %>% filter(!is.na(device)) %>%
    ggplot(aes(x = device, y = toot_length)) + 
           geom_dotplot(binaxis='y', stackdir='center', dotsize = 0.5)
#> Bin width defaults to 1/30 of the range of the data. Pick better value with `binwidth`.

Created on 2022-11-28 by the reprex package (v2.0.1)

Clone this wiki locally