diff --git a/00_first-run.R b/00_first-run.R index 234c88b..fd2ec09 100644 --- a/00_first-run.R +++ b/00_first-run.R @@ -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, diff --git a/R/custom/00_settings.R b/R/custom/00_settings.R index 4572793..6939964 100644 --- a/R/custom/00_settings.R +++ b/R/custom/00_settings.R @@ -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 diff --git a/R/functions.R b/R/functions.R index 8361198..6cec276 100644 --- a/R/functions.R +++ b/R/functions.R @@ -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)