MyNixOS website logo
Description

Parse and Validate Tweet Text.

An interface to 'twitter-text', a 'JavaScript' library which is responsible for determining the length/validity of a tweet and identifying/linking any URLs or special tags (e.g. mentions or hashtags) which may be present.

R-CMD-check

tweetcheck

{tweetcheck} is a simple R wrapper for the twitter-text JavaScript library which is made available by Twitter under the Apache 2.0 license. This library allows easy parsing of tweet text as well as autolinking and extraction of mentions.

Installation

# Install from CRAN using:
install.packages("tweetcheck")

# Install from GitHub using:
remotes::install_github("wurli/tweetcheck")

Demo

Parse tweet information

library(tweetcheck)

tweets <- c(
  "This is a first tweet. Simple!",
  "This tweet tags @hadleywickham and @_wurli",
  "This tweet links {rtweet}: https://docs.ropensci.org/rtweet/",
  "Emojis take up two characters 😄😄😄",
  "Some may have hashtags or cashtags: #RStats $RSTATS",
  strrep("This tweet is way too long! ", 20)
)

tweet_info(tweets)
#> # A tibble: 6 × 8
#>   tweet                  weigh…¹ is_va…² permi…³ valid…⁴ valid…⁵ displ…⁶ displ…⁷
#>   <chr>                    <int> <lgl>     <dbl>   <int>   <int>   <int>   <int>
#> 1 "This is a first twee…      30 TRUE      0.107       1      30       1      30
#> 2 "This tweet tags @had…      42 TRUE      0.15        1      42       1      42
#> 3 "This tweet links {rt…      50 TRUE      0.178       1      60       1      60
#> 4 "Emojis take up two c…      36 TRUE      0.128       1      36       1      36
#> 5 "Some may have hashta…      51 TRUE      0.182       1      51       1      51
#> 6 "This tweet is way to…     560 FALSE     2           1     280       1     560
#> # … with abbreviated variable names ¹​weighted_length, ²​is_valid, ³​permillage,
#> #   ⁴​valid_range_start, ⁵​valid_range_end, ⁶​display_range_start,
#> #   ⁷​display_range_end

tweet_permillage(), tweet_weighted_length(), tweet_is_valid(), tweet_valid_range_start(), tweet_valid_range_end(), tweet_display_range_start(), and tweet_display_range_end() are convenience functions which can be used to extract any of the above columns individually.

Extract mentions

tweet_get_mentions(tweets)
#> [[1]]
#> character(0)
#> 
#> [[2]]
#> [1] "hadleywickham" "_wurli"       
#> 
#> [[3]]
#> character(0)
#> 
#> [[4]]
#> character(0)
#> 
#> [[5]]
#> character(0)
#> 
#> [[6]]
#> character(0)

Perform autolinking

tweet_autolink(tweets)
#> [1] "This is a first tweet. Simple!"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
#> [2] "This tweet tags @<a class=\"tweet-url username\" href=\"https://twitter.com/hadleywickham\" data-screen-name=\"hadleywickham\" rel=\"nofollow\">hadleywickham</a> and @<a class=\"tweet-url username\" href=\"https://twitter.com/_wurli\" data-screen-name=\"_wurli\" rel=\"nofollow\">_wurli</a>"                                                                                                                                                                                                                                                                              
#> [3] "This tweet links {rtweet}: <a href=\"https://docs.ropensci.org/rtweet/\" rel=\"nofollow\">https://docs.ropensci.org/rtweet/</a>"                                                                                                                                                                                                                                                                                                                                                                                                                                                 
#> [4] "Emojis take up two characters 😄😄😄"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
#> [5] "Some may have hashtags or cashtags: <a href=\"https://twitter.com/search?q=%23RStats\" title=\"#RStats\" class=\"tweet-url hashtag\" rel=\"nofollow\">#RStats</a> <a href=\"https://twitter.com/search?q=%24RSTATS\" title=\"$RSTATS\" class=\"tweet-url cashtag\" rel=\"nofollow\">$RSTATS</a>"                                                                                                                                                                                                                                                                                 
#> [6] "This tweet is way too long! This tweet is way too long! This tweet is way too long! This tweet is way too long! This tweet is way too long! This tweet is way too long! This tweet is way too long! This tweet is way too long! This tweet is way too long! This tweet is way too long! This tweet is way too long! This tweet is way too long! This tweet is way too long! This tweet is way too long! This tweet is way too long! This tweet is way too long! This tweet is way too long! This tweet is way too long! This tweet is way too long! This tweet is way too long! "

See also

{rtweet} is a package which allows easy interaction with the Twitter API for actions such as posting or downloading of tweets. {V8} is a package which allows JavaScript code to be called from R and is used by {tweetcheck}.

Metadata

Version

0.1.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows