Title: | Parse and Validate Tweet Text |
---|---|
Description: | 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. |
Authors: | Jacob Scott [aut, cre], Twitter, Inc [aut], Other contributors [aut] |
Maintainer: | Jacob Scott <[email protected]> |
License: | Apache License (>= 2) |
Version: | 0.1.0 |
Built: | 2024-11-10 05:30:25 UTC |
Source: | https://github.com/wurli/tweetcheck |
Perform tweet autolinking
tweet_autolink(x)
tweet_autolink(x)
x |
A character vector of tweets to be autolinked |
A character vector giving the HTML which would be used by Twitter
if x
were posted as a tweet.
tweet_autolink(c( "Tweet with no links", "Tweet with a normal link: https://www.r-project.org", "Tweet with a mention @hadleywickham", "Tweet with a hastag: #RStats", "Tweet with a cashtag: $RSTATS" ))
tweet_autolink(c( "Tweet with no links", "Tweet with a normal link: https://www.r-project.org", "Tweet with a mention @hadleywickham", "Tweet with a hastag: #RStats", "Tweet with a cashtag: $RSTATS" ))
Extract mentions from a tweet
tweet_get_mentions(x)
tweet_get_mentions(x)
x |
A character vector of tweets to extract mentions for |
A list with length(x)
elements, where each element is a character
vector of mentions. Mentions have the '@' character removed.
tweet_get_mentions(c("No mentions", "One mention @_wurli"))
tweet_get_mentions(c("No mentions", "One mention @_wurli"))
These functions can be used to validate tweets before posting.
tweet_info(x) tweet_permillage(x) tweet_weighted_length(x) tweet_is_valid(x) tweet_valid_range_start(x) tweet_valid_range_end(x) tweet_display_range_start(x) tweet_display_range_end(x)
tweet_info(x) tweet_permillage(x) tweet_weighted_length(x) tweet_is_valid(x) tweet_valid_range_start(x) tweet_valid_range_end(x) tweet_display_range_start(x) tweet_display_range_end(x)
x |
A character vector of tweet |
tweet_info()
: <tbl_df>
with columns for all the
following fields, as well as a column tweet
giving the original text.
Note that this function is called internally by all of the following,
so it may be more efficient to store this result and extract columns as
needed.
tweet_permillage()
: <numeric>
indicating the number of characters
used as a proportion of the maximum number of characters allowed. I.e.
this will be > 0 and <= 1 for valid tweets.
tweet_weighted_length()
: <integer>
indicating the 'length' of the tweet
according to Twitter's parsing rules. The maximum allowed length is 280
characters.
tweet_is_valid()
: <logical>
indicating whether or not the tweet is
valid according to Twitter's parsing rules
tweet_valid_range_start()
/tweet_valid_range_end()
: <integer>
indicating the index of the first/last characters of the valid range of a
tweet
tweet_display_range_start()
/tweet_display_range_end()
: <integer>
indicating the index of the first/last characters of the display range of
a tweet
tweet_info()
returns a dataframe with length(x)
rows. The other
functions return integer/numeric vectors with length(x)
elements.
tweet_get_mentions()
and tweet_autolink()
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 \U1F600\U1F600\U1F600", strrep("This tweet is way too long! ", 20) ) # Dataframe summarising all of the following tweet_info(tweets) # Ratio of used characterss to allowed characters tweet_permillage(tweets) # Length of the tweet (according to Twitter's rules): tweet_weighted_length(tweets) # Logical indicating tweet validity: tweet_is_valid(tweets) # Valid range of a tweet tweet_valid_range_start(tweets) tweet_valid_range_end(tweets) # Display range of a tweet tweet_display_range_start(tweets) tweet_display_range_end(tweets)
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 \U1F600\U1F600\U1F600", strrep("This tweet is way too long! ", 20) ) # Dataframe summarising all of the following tweet_info(tweets) # Ratio of used characterss to allowed characters tweet_permillage(tweets) # Length of the tweet (according to Twitter's rules): tweet_weighted_length(tweets) # Logical indicating tweet validity: tweet_is_valid(tweets) # Valid range of a tweet tweet_valid_range_start(tweets) tweet_valid_range_end(tweets) # Display range of a tweet tweet_display_range_start(tweets) tweet_display_range_end(tweets)