ソースを参照

Use dplyr::bind_rows() instead of rbind()

simplify
コミット
cd0ef8c4a6
4個のファイルの変更13行の追加8行の削除
  1. +1
    -0
      DESCRIPTION
  2. +2
    -0
      NAMESPACE
  3. +1
    -0
      R/gathertweet-package.R
  4. +9
    -8
      R/tweet_io.R

+ 1
- 0
DESCRIPTION ファイルの表示

Imports: Imports:
digest, digest,
docopt, docopt,
dplyr,
filelock, filelock,
fs, fs,
futile.logger, futile.logger,

+ 2
- 0
NAMESPACE ファイルの表示

export(save_tweets) export(save_tweets)
export(update_tweets) export(update_tweets)
import(filelock) import(filelock)
importFrom(dplyr,anti_join)
importFrom(dplyr,bind_rows)
importFrom(fs,dir_exists) importFrom(fs,dir_exists)
importFrom(fs,file_exists) importFrom(fs,file_exists)
importFrom(fs,path) importFrom(fs,path)

+ 1
- 0
R/gathertweet-package.R ファイルの表示

#' @keywords internal #' @keywords internal
#' @importFrom fs dir_exists file_exists path #' @importFrom fs dir_exists file_exists path
#' @importFrom dplyr bind_rows anti_join
#' @importFrom tibble tibble #' @importFrom tibble tibble
#' @import filelock #' @import filelock
"_PACKAGE" "_PACKAGE"

+ 9
- 8
R/tweet_io.R ファイルの表示

if (fs::file_exists(file)) { if (fs::file_exists(file)) {
# Don't drop or lose old tweets # Don't drop or lose old tweets
tweets_prev <- read_fun(file, lck = lck) tweets_prev <- read_fun(file, lck = lck)
status_not_new <- setdiff(tweets_prev$status_id, tweets$status_id)
if (length(status_not_new)) {
tweets <- rbind(
tweets,
tweets_prev[tweets_prev$status_id %in% status_not_new, ]
)
if (!is.null(tweets_prev)) {
tweets_not_new <- anti_join(tweets_prev, tweets, by = "status_id")
if (nrow(tweets_not_new)) {
tweets <- bind_rows(tweets, tweets_not_new)
}
if (length(setdiff(tweets_prev$status_id, tweets$status_id)) == 0) {
log_fatal("An error occurred that would have lost stored tweets")
}
} }
stopifnot(length(setdiff(tweets_prev$status_id, tweets$status_id)) == 0)
} }


save_fun(tweets, file) save_fun(tweets, file)
idx_end <- n_status idx_end <- n_status
log_info("Getting {n_status} tweets") log_info("Getting {n_status} tweets")
} }
tweets <- rbind(
tweets <- bind_rows(
tweets, tweets,
rtweet::lookup_statuses(status_id[idx_start:idx_end]) rtweet::lookup_statuses(status_id[idx_start:idx_end])
) )

読み込み中…
キャンセル
保存