Skip to content

Commit

Permalink
Update language and instructions for rtweet token
Browse files Browse the repository at this point in the history
for #2
  • Loading branch information
gadenbuie committed Sep 1, 2019
1 parent 75c7759 commit ec37842
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
4 changes: 3 additions & 1 deletion 00_first-run.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ if (!file.exists(here::here("data", "tweets_oembed.rds"))) {
TWEETS_FILE <- TWEETS_FILE %>% keep(file.exists) %>% .[1]
message("Using tweets from: ", TWEETS_FILE)

if (requireNamespace("furrr", quietly = TRUE)) {
if (ALLOW_PARALLEL && requireNamespace("furrr", quietly = TRUE)) {
message("Using {furrr} to speed up the process")
future::plan(future::multisession)
} else {
message("(Set `ALLOW_PARALLEL = TRUE`` in 00_settings.R and install {furrr} to speed this up.)")
}
tweets <- import_tweets(
TWEETS_FILE,
Expand Down
38 changes: 19 additions & 19 deletions R/custom/00_settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,31 @@ TWEETS_MANAGE_UPDATES <- TRUE
# fine. Updates are done incrementally (new tweets only) unless it has been more
# than 2 hours since last update or within a window around the start of the hour.
TWEETS_MANAGE_UPDATE_INTERVAL <- 5 * 60
# Location of your Twitter PAT from {rtweet}. See {rtweet} for help
# authenicating your app with Twitter. Then view your users .Renviron (you can
# use `usethis::edit_r_environ()`) to locate the RDS containing your PAT.
# If you're deploying on shinyapps.io or elsewhere you should copy this RDS file
# into your project (usually it's `~/.rtweet_token.rds`) and set the variable
# below to the correct file name. DON'T COMMIT THIS FILE TO VERSION CONTROL!!
TWEETS_MANAGE_TWITTER_PAT_RDS <- ".rtweet_token.rds"

if (TWEETS_MANAGE_UPDATES) {
# Check that TWITTER_PAT is correctly set
# Check that TWITTER_PAT is available. See {rtweet} for help authenticating
# your app with Twitter. Then view your users .Renviron (you can use
# `usethis::edit_r_environ()`) to locate the RDS containing your PAT. If
# you're deploying on shinyapps.io or elsewhere you should copy this RDS file
# into your project (usually it's `~/.rtweet_token.rds`) and add
#
# TWITTER_PAT=".rtweet_token.rds"
#
# to your project .Renviron (run `usethis::edit_r_environ("project")`).
# DON'T COMMIT THE RTWEET TOKEN RDS FILE TO VERSION CONTROL!!
if (Sys.getenv("TWITTER_PAT") == "") {
if (file.exists(TWEETS_MANAGE_TWITTER_PAT_RDS)) {
Sys.setenv(TWITTER_PAT = TWEETS_MANAGE_TWITTER_PAT_RDS)
} else {
warning(
"I can't find the file containing your Twitter PAT, so live ",
"updating with {rtweet} won't be possible. See {rtweet} for help ",
"authenticating and set the config TWEETS_MANAGE_TWITTER_PAT_RDS in ",
"'R/custom/00_settings.R'."
)
TWEETS_MANAGE_UPDATES <- FALSE
}
warning(
"I can't find the file containing your Twitter PAT, so live ",
"updating with {rtweet} won't be possible. See {rtweet} for help ",
"authenticating and set the config TWEETS_MANAGE_TWITTER_PAT_RDS in ",
"'R/custom/00_settings.R'."
)
TWEETS_MANAGE_UPDATES <- FALSE
}
}

ALLOW_PARALLEL <- FALSE

# ----- Tweets With Most XX Time Window ----
# Sets the time window for the "Top RT" and "Top Liked" tweets on the front
# page. Shows the top tweet from the last `hours + days + minutes`, and the text
Expand Down
4 changes: 3 additions & 1 deletion R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ tweet_cache_oembed <- function(tweets, cache = "data/tweets_oembed.rds") {

is_needed <- map_lgl(tweets$oembed, is.null)
if (any(is_needed)) {
tweets$oembed[is_needed] <- if (requireNamespace("furrr", quietly = TRUE)) {
tweets$oembed[is_needed] <- if (
ALLOW_PARALLEL && requireNamespace("furrr", quietly = TRUE)
) {
furrr::future_pmap(tweets[is_needed, ], get_tweet_blockquote, null_on_error = FALSE, .progress = TRUE)
} else {
pmap(tweets[is_needed, ], get_tweet_blockquote, null_on_error = FALSE)
Expand Down

0 comments on commit ec37842

Please sign in to comment.