Set up a StackOverflow twitter bot for a given list of tags, and excluded tags. Job scheduling can be set up using either cronR or taskscheduleR depending on your platform.

set_up_stack_tweet_bot(name = "stack_tweet_bot", extracted_tags = NULL,
  excluded_tags = NULL, time_window = 60, add_process_fn = NULL,
  hashtags = "rstats", post = TRUE, dir = NULL, run = TRUE,
  schedule = TRUE, save = TRUE, verbose = TRUE, ...)

Arguments

name

Character string containing the bots name, defaults to "stack_tweet_bot".

extracted_tags

A character vector of tags to extract questions for.

excluded_tags

A character vector of tags to exclude questions from the output.

time_window

Numeric, the timewindow to extract questions for (in minutes. Defaults to 60 minutes. Note that a maximum of 100 questions are extracted by the StackOverflow api, if you expect your tags to have a high volume of questions reduce this. If using this function as part of a sheduled bot makes sure this time frame corresponds the frequency with which your bot is running.

add_process_fn

A function. If additional munging or data extraction is required add to a custom function and pass here. This function must except a dataframe as its first arguement and return a dataframe. See the examples for details.

hashtags

A character vector of hashtags to attach to the tweet. See add_twitter_api for details.

post

Logical, defaults to TRUE. Should the formatted tweets be published on twitter, if FALSE then the tweets are instead returned as a list.

dir

Character string containing the directory into which to save the bot, defaults to the temporary directory. Is not used if save = FALSE.

run

Logical, defaults to TRUE. Should the bot be run once saved?

schedule

Logical, defaults to TRUE. Should the bot be scheduled to run using cronR/taskscheduleR? In order to schedule the bot save must be TRUE.

save

Logical, defaults to TRUE. Should the bot be saved.

verbose

Logical, defaults to TRUE. Should progress messages be printed to the terminal.

...

Additional arguements to pass to cron_add or taskscheduler_create when schedule = TRUE.The suggested frequency for the bot run is hourly, set this by passing frequency = "hourly" (cronR) or schedule = "HOURLY" (taskscheduleR).

Value

A character string containing the twitter bot code.

See also

Examples

## Build and run twitter bot set_up_stack_tweet_bot(extracted_tags = "ggplot2", time_window = 60 * 48, run = TRUE, schedule = FALSE, save = TRUE, post = FALSE)
#> No directory has been supplied for saving the twitter bot, #> defaulting to saving to the temporary directory. This directory will not be #> preserved once the r session has ended.
#> Saving the following code to: /tmp/RtmprQyGkR/stack_tweet_bot.R
#> Code: #> #> library(StackTweetBot); #> #> message('Getting Stack Overflow questions at ', Sys.time()); #> #> questions <- get_stack_questions(extracted_tags = 'ggplot2', #> excluded_tags = NULL, #> time_window = 2880, #> add_process_fn = NULL); #> #> message('Extracted ', length(questions$title), ' questions'); #> #> message('Posting questions as tweets'); #> #> posts <- post_stack_tweets(questions, hashtags = 'rstats', #> post = FALSE);
#> Running bot..
#> Getting Stack Overflow questions at 2018-10-24 15:52:30
#> Extracted 44 questions
#> Posting questions as tweets
#> library(StackTweetBot); #> #> message('Getting Stack Overflow questions at ', Sys.time()); #> #> questions <- get_stack_questions(extracted_tags = 'ggplot2', #> excluded_tags = NULL, #> time_window = 2880, #> add_process_fn = NULL); #> #> message('Extracted ', length(questions$title), ' questions'); #> #> message('Posting questions as tweets'); #> #> posts <- post_stack_tweets(questions, hashtags = 'rstats', #> post = FALSE);
## Sample bot output posts
#> [[1]] #> How to assign colors using a variable containing color names in a grouped ggplot? (r,ggplot2) #rstats https://stackoverflow.com/questions/52934113/how-to-assign-colors-using-a-variable-containing-color-names-in-a-grouped-ggplot #> #> [[2]] #> Linetype for points in ggplot2 (r,ggplot2) #rstats https://stackoverflow.com/questions/52936464/linetype-for-points-in-ggplot2 #> #> [[3]] #> Obtaining 4 barplots in a panel - error obtained running a previous stackoverflow example (r,ggplot2,bar-chart) #rstats https://stackoverflow.com/questions/52936480/obtaining-4-barplots-in-a-panel-error-obtained-running-a-previous-stackoverflo #> #> [[4]] #> Plot a data frame as a grouped bar plot (r,ggplot2) #rstats https://stackoverflow.com/questions/52937533/plot-a-data-frame-as-a-grouped-bar-plot #> #> [[5]] #> Custom legend in ggplot2: how to fill without factors? (r,ggplot2) #rstats https://stackoverflow.com/questions/52937729/custom-legend-in-ggplot2-how-to-fill-without-factors #> #> [[6]] #> Facet_wrap: conditional formatting based on label_value? (r,ggplot2,facet-wrap) #rstats https://stackoverflow.com/questions/52938113/facet-wrap-conditional-formatting-based-on-label-value #> #> [[7]] #> "Reversed" use of fct_infreq() in ggplot2 (r,ggplot2) #rstats https://stackoverflow.com/questions/52938858/reversed-use-of-fct-infreq-in-ggplot2 #> #> [[8]] #> ggplot legend with geom_rect (r,ggplot2,plot,legend) #rstats https://stackoverflow.com/questions/52938883/ggplot-legend-with-geom-rect #> #> [[9]] #> Adding points, symbols, and legends to ggplot (r,ggplot2,plot,legend) #rstats https://stackoverflow.com/questions/52939108/adding-points-symbols-and-legends-to-ggplot #> #> [[10]] #> Plotting interaction with two categorical variables and baseline control (r,ggplot2) #rstats https://stackoverflow.com/questions/52940649/plotting-interaction-with-two-categorical-variables-and-baseline-control #> #> [[11]] #> How to set free facet_wrap y-axis range so that it caps the maximum data point? (r,ggplot2,data-visualization,facet-wrap) #rstats https://stackoverflow.com/questions/52947232/how-to-set-free-facet-wrap-y-axis-range-so-that-it-caps-the-maximum-data-point #> #> [[12]] #> color cells of facet_grid according to cluster (r,ggplot2) #rstats https://stackoverflow.com/questions/52943712/color-cells-of-facet-grid-according-to-cluster #> #> [[13]] #> how to use ggplot function to plot (r,ggplot2) #rstats https://stackoverflow.com/questions/52944299/how-to-use-ggplot-function-to-plot #> #> [[14]] #> Controlling x-labels in facet_wrap ggplot2 (r,ggplot2) #rstats https://stackoverflow.com/questions/52945477/controlling-x-labels-in-facet-wrap-ggplot2 #> #> [[15]] #> stat_compare_means anova on selected groups (r,ggplot2,ggpubr) #rstats https://stackoverflow.com/questions/52945554/stat-compare-means-anova-on-selected-groups #> #> [[16]] #> Using expand_limits in ggplot when counts are not a column in the dataset (R) (r,ggplot2,geom-bar) #rstats https://stackoverflow.com/questions/52945930/using-expand-limits-in-ggplot-when-counts-are-not-a-column-in-the-dataset-r #> #> [[17]] #> Lines in ggplot with segment function (r,ggplot2) #rstats https://stackoverflow.com/questions/52946413/lines-in-ggplot-with-segment-function #> #> [[18]] #> how can I describe the model ad and bpd? (r,ggplot2) #rstats https://stackoverflow.com/questions/52947877/how-can-i-describe-the-model-ad-and-bpd #> #> [[19]] #> Graph differences between groups in ggplot2 (r,ggplot2) #rstats https://stackoverflow.com/questions/52947992/graph-differences-between-groups-in-ggplot2 #> #> [[20]] #> Align ggplot legend automatically to width of a plot in R (r,ggplot2,legend) #rstats https://stackoverflow.com/questions/52948011/align-ggplot-legend-automatically-to-width-of-a-plot-in-r #> #> [[21]] #> R: ggplot2 let the characters of geom_text exactly cover one X unit (r,ggplot2,text) #rstats https://stackoverflow.com/questions/52948760/r-ggplot2-let-the-characters-of-geom-text-exactly-cover-one-x-unit #> #> [[22]] #> How do I make a plot using ggplot (R studio) in which items are separated by a categorising column? (r,ggplot2,facet-grid) #rstats https://stackoverflow.com/questions/52949718/how-do-i-make-a-plot-using-ggplot-r-studio-in-which-items-are-separated-by-a-c #> #> [[23]] #> How to avoid clipping of labels with ggtern/ggplot2 (like xpd=TRUE) (r,ggplot2,label,clipping,ggtern) #rstats https://stackoverflow.com/questions/52950385/how-to-avoid-clipping-of-labels-with-ggtern-ggplot2-like-xpd-true #> #> [[24]] #> Colouring by derived continuous variable in ggplot2 box or barplot (r,ggplot2,dplyr,statistics,boxplot) #rstats https://stackoverflow.com/questions/52951291/colouring-by-derived-continuous-variable-in-ggplot2-box-or-barplot #> #> [[25]] #> xlim in ggplot with POSIXct dates (r,ggplot2) #rstats https://stackoverflow.com/questions/52951740/xlim-in-ggplot-with-posixct-dates #> #> [[26]] #> ggplot2 - Correctly arrange odd number of plots into one figure (r,ggplot2,cowplot) #rstats https://stackoverflow.com/questions/52953569/ggplot2-correctly-arrange-odd-number-of-plots-into-one-figure #> #> [[27]] #> Plotting monthly percentages in shiny R (r,ggplot2,shiny,shinydashboard) #rstats https://stackoverflow.com/questions/52954681/plotting-monthly-percentages-in-shiny-r #> #> [[28]] #> ggplot order of geom_point and geom_line differ (r,ggplot2) #rstats https://stackoverflow.com/questions/52954846/ggplot-order-of-geom-point-and-geom-line-differ #> #> [[29]] #> How do I annotate a ggtree object with bootstrap values? (r,ggplot2,bioinformatics,phylogeny,ggtree) #rstats https://stackoverflow.com/questions/52956181/how-do-i-annotate-a-ggtree-object-with-bootstrap-values #> #> [[30]] #> How to annotate different values for each facet with dodged geom_boxplot on R? (r,ggplot2,text,boxplot) #rstats https://stackoverflow.com/questions/52958453/how-to-annotate-different-values-for-each-facet-with-dodged-geom-boxplot-on-r #> #> [[31]] #> How to fix the multiple error bar issue of ggplot in R? (ggplot2,errorbar) #rstats https://stackoverflow.com/questions/52960261/how-to-fix-the-multiple-error-bar-issue-of-ggplot-in-r #> #> [[32]] #> No legend in ggplot line graph (r,ggplot2,legend,linegraph) #rstats https://stackoverflow.com/questions/52960885/no-legend-in-ggplot-line-graph #> #> [[33]] #> Choropleth Plotting polygons with ggplot2 R on a map (r,ggplot2,gis,ggmap) #rstats https://stackoverflow.com/questions/52961807/choropleth-plotting-polygons-with-ggplot2-r-on-a-map #> #> [[34]] #> Why do I get the weird purple line in ggplot? (r,ggplot2) #rstats https://stackoverflow.com/questions/52961934/why-do-i-get-the-weird-purple-line-in-ggplot #> #> [[35]] #> R (ggplot2): line with data labels (r,ggplot2) #rstats https://stackoverflow.com/questions/52962517/r-ggplot2-line-with-data-labels #> #> [[36]] #> ggplot y axis adjustment and statistics (r,ggplot2,ggpubr) #rstats https://stackoverflow.com/questions/52966608/ggplot-y-axis-adjustment-and-statistics #> #> [[37]] #> How to install ggplot2 for R to a custom lib directory (r,ggplot2,installation,package) #rstats https://stackoverflow.com/questions/52967249/how-to-install-ggplot2-for-r-to-a-custom-lib-directory #> #> [[38]] #> ggplot2: can geom_point work in melted dataframes? (r,ggplot2,scatter-plot,dcast) #rstats https://stackoverflow.com/questions/52968996/ggplot2-can-geom-point-work-in-melted-dataframes #> #> [[39]] #> Framework for adding lines on existing plots: "points" and "plot" in ggplot (r,ggplot2) #rstats https://stackoverflow.com/questions/52970305/framework-for-adding-lines-on-existing-plots-points-and-plot-in-ggplot #> #> [[40]] #> grouped barplot from table (r,ggplot2,bar-chart) #rstats https://stackoverflow.com/questions/52970306/grouped-barplot-from-table #> #> [[41]] #> ggplot: Show 24-hour activity profiles for each day through 48 weeks (r,ggplot2,plot) #rstats https://stackoverflow.com/questions/52972439/ggplot-show-24-hour-activity-profiles-for-each-day-through-48-weeks #> #> [[42]] #> ggplot2: grouping a barplot by several instead of a single categorical variable (r,ggplot2) #rstats https://stackoverflow.com/questions/52973023/ggplot2-grouping-a-barplot-by-several-instead-of-a-single-categorical-variable #> #> [[43]] #> Plotting multiple densities in ggplot2: How to add an extra variable with a different scale? (r,ggplot2,scaling) #rstats https://stackoverflow.com/questions/52973132/plotting-multiple-densities-in-ggplot2-how-to-add-an-extra-variable-with-a-diff #> #> [[44]] #> How to pass a string argument to expression function in ggplot2? (ggplot2) #rstats https://stackoverflow.com/questions/52973186/how-to-pass-a-string-argument-to-expression-function-in-ggplot2 #>