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

Commit 3301254

Browse files
authored
Merge pull request #92 from medewitt/bind-error
updating test and returning error if no files are found
2 parents 9180a2a + f2a49b3 commit 3301254

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

R/bind_tweet_jsons.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ bind_tweet_jsons <- function(data_path) {
2121
recursive = T,
2222
include.dirs = T
2323
)
24+
25+
if(length(files)<1){
26+
stop("There are no files matching the pattern `data_` in the specified directory.")
27+
}
28+
2429
files <- paste(data_path, files, sep = "")
2530

2631
pb = utils::txtProgressBar(min = 0,
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1+
context("bind_tweet_jsons")
2+
13

24
empty_dir <- tempdir()
3-
jsonlite::write_json(jsonlite::toJSON(mtcars),
5+
6+
my_cars <- mtcars
7+
my_cars$model <- rownames(my_cars)
8+
9+
jsonlite::write_json(my_cars,
410
path = file.path(empty_dir, "data_1.json"))
5-
jsonlite::write_json(jsonlite::toJSON(mtcars),
11+
jsonlite::write_json(my_cars,
612
path = file.path(empty_dir, "data_2.json"))
713

8-
test_that("Error on non-twitter json binding", {
9-
expect_error(bind_tweet_jsons(empty_dir))
14+
test_that("Expect sucess in binding two jsons", {
15+
expect_equal(bind_tweet_jsons(empty_dir),
16+
dplyr::bind_rows(my_cars,my_cars))
1017
})
18+
19+
unlink(empty_dir, recursive = TRUE)
20+
temp_dir <- tempdir()
21+
22+
test_that("Error on finding no jsons to bind", {
23+
expect_error(bind_tweet_jsons(temp_dir))
24+
})
25+

0 commit comments

Comments
 (0)