Skip to content
This repository was archived by the owner on Jun 30, 2023. It is now read-only.

Commit 12f35cd

Browse files
authored
Merge pull request #354 from TimBMK/furrr-support
Furrr support
2 parents 3f0b0ef + e34436b commit 12f35cd

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

DESCRIPTION

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ URL: https://github.com/cjbarrie/academictwitteR
4343
BugReports: https://github.com/cjbarrie/academictwitteR/issues
4444
Encoding: UTF-8
4545
Roxygen: list(markdown = TRUE)
46-
RoxygenNote: 7.1.2
46+
RoxygenNote: 7.2.1
4747
Depends:
4848
R (>= 3.4)
4949
Imports:
@@ -58,7 +58,9 @@ Imports:
5858
tidyselect,
5959
purrr,
6060
rlang,
61-
utils
61+
utils,
62+
future,
63+
furrr
6264
Suggests:
6365
knitr,
6466
rmarkdown,

R/bind_tweets.R

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#' By default, `bind_tweets` binds into a data frame containing tweets (from data_*id*.json files).
66
#'
77
#' If users is TRUE, it binds into a data frame containing user information (from users_*id*.json).
8+
#'
9+
#' For the "tidy" format, parallel processing with furrr is supported. In order to enable parallel processing, workers need to be set manually through [future::plan()]. See examples
810
#'
911
#' @param data_path string, file path to directory of stored tweets data saved as data_*id*.json and users_*id*.json
1012
#' @param user If `FALSE`, this function binds JSON files into a data frame containing tweets; data frame containing user information otherwise. Ignore if `output_format` is not NA
@@ -15,6 +17,7 @@
1517
#' \item{"raw"}{List of data frames; Note: not all data frames are in Boyce-Codd 3rd Normal Form}
1618
#' \item{"tidy"}{Tidy format; all essential columns are available}
1719
#' }
20+
#'
1821
#' @return a data.frame containing either tweets or user information
1922
#' @export
2023
#'
@@ -28,7 +31,16 @@
2831
#'
2932
#' # bind json files in the directory "data" into a "tidy" data frame / tibble
3033
#' bind_tweets(data_path = "data/", user = TRUE, output_format = "tidy")
34+
#'
35+
#' # bind json files in the directory "data" into a "tidy" data frame / tibble with parallel computing
36+
#' ## set up a multisession
37+
#' future::plan("multisession")
38+
#' ## run the function - note that no additional arguments are required
39+
#' bind_tweets(data_path = "data/", user = TRUE, output_format = "tidy")
40+
#' ## Shut down parallel workers
41+
#' future::plan("sequential")
3142
#' }
43+
#'
3244
bind_tweets <- function(data_path, user = FALSE, verbose = TRUE, output_format = NA) {
3345
if (!is.na(output_format)) {
3446
return(.flat(data_path, output_format = output_format))
@@ -142,7 +154,7 @@ convert_json <- function(data_file, output_format = "tidy") {
142154
if (output_format == "raw") {
143155
return(convert_json(data_files, output_format = "raw"))
144156
}
145-
return(purrr::map_dfr(data_files, convert_json, output_format = output_format))
157+
return(furrr::future_map_dfr(data_files, convert_json, output_format = output_format))
146158
}
147159

148160
.gen_raw <- function(df, pkicol = "id", pki_name = "tweet_id") {

man/bind_tweets.Rd

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)