-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from ijlyttle/master
Pagination, thanks to Ian Lyttle!
- Loading branch information
Showing
4 changed files
with
138 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ Imports: | |
Suggests: | ||
testthat, | ||
knitr, | ||
rmarkdown | ||
rmarkdown, | ||
purrr | ||
VignetteBuilder: knitr | ||
RoxygenNote: 5.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
context("Listing remote files") | ||
|
||
# function to create a file in a local directory | ||
# | ||
# @param x numeric, number of the file | ||
# @param dir character, name of the directory | ||
# | ||
fn_create <- function(x, dir){ | ||
|
||
name <- paste0("file_", formatC(x, width = 4, flag = "0"), ".txt") | ||
filename <- file.path(dir_ls, name) | ||
|
||
writeLines("test file", filename) | ||
} | ||
|
||
# given a boxr_object_list, return a vector of names | ||
# | ||
# @param b boxr_object_list | ||
# | ||
get_filenames <- function(b){ | ||
b %>% | ||
as.data.frame() %>% | ||
dplyr::arrange(name) %>% | ||
`[[`("name") | ||
} | ||
|
||
test_that("file listing works", { | ||
|
||
skip_on_cran() | ||
boxr:::skip_on_travis() | ||
|
||
# (Re)create local dir structure | ||
boxr:::create_test_dir() | ||
|
||
# create ls directory | ||
dir_ls <- file.path("test_dir", "ls") | ||
dir.create(dir_ls) | ||
|
||
# create files in the ls directory | ||
purrr::walk(seq_len(10), fn_create, dir_ls) | ||
|
||
files_local <- list.files(dir_ls) | ||
|
||
# push the local directory | ||
box_push(0, "test_dir", overwrite = TRUE, delete = TRUE) | ||
|
||
# get the id of the remote ld directory | ||
id_ls <- | ||
box_ls(0) %>% | ||
as.data.frame() %>% | ||
dplyr::filter(name == "ls") %>% | ||
dplyr::select(id) %>% | ||
`[[`(1) %>% | ||
as.numeric() | ||
|
||
# get the listing without pagination | ||
files_box <- | ||
box_ls(id_ls) %>% | ||
get_filenames() | ||
|
||
# get the listing with pagination | ||
files_box_page <- | ||
box_ls(id_ls, limit = 5) %>% | ||
get_filenames() | ||
|
||
# test | ||
expect_identical(files_box, files_local) | ||
expect_identical(files_box_page, files_local) | ||
|
||
}) |