소스 검색

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

simplify
Garrick Aden-Buie 7 년 전
부모
커밋
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 파일 보기

@@ -14,6 +14,7 @@ License: MIT + file LICENSE
Imports:
digest,
docopt,
dplyr,
filelock,
fs,
futile.logger,

+ 2
- 0
NAMESPACE 파일 보기

@@ -15,6 +15,8 @@ export(read_tweets)
export(save_tweets)
export(update_tweets)
import(filelock)
importFrom(dplyr,anti_join)
importFrom(dplyr,bind_rows)
importFrom(fs,dir_exists)
importFrom(fs,file_exists)
importFrom(fs,path)

+ 1
- 0
R/gathertweet-package.R 파일 보기

@@ -1,5 +1,6 @@
#' @keywords internal
#' @importFrom fs dir_exists file_exists path
#' @importFrom dplyr bind_rows anti_join
#' @importFrom tibble tibble
#' @import filelock
"_PACKAGE"

+ 9
- 8
R/tweet_io.R 파일 보기

@@ -17,14 +17,15 @@ save_tweets <- function(
if (fs::file_exists(file)) {
# Don't drop or lose old tweets
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)
@@ -118,7 +119,7 @@ lookup_status_ratelimit <- function(status_id, ...) {
idx_end <- n_status
log_info("Getting {n_status} tweets")
}
tweets <- rbind(
tweets <- bind_rows(
tweets,
rtweet::lookup_statuses(status_id[idx_start:idx_end])
)

Loading…
취소
저장