|
1 | | -apply_by_pages <- function(x, FUN, pagesize, verbose, ...){ |
| 1 | +apply_by_pages <- function(x, FUN, pagesize, verbose, ...) { |
2 | 2 | stopifnot(is.data.frame(x)) |
3 | 3 | nr <- nrow(x) |
4 | | - npages <- nr %/% pagesize; |
5 | | - lastpage <- nr %% pagesize; |
| 4 | + npages <- nr %/% pagesize |
| 5 | + lastpage <- nr %% pagesize |
6 | 6 |
|
7 | 7 | out <- as.list(rep(NA, npages + as.logical(lastpage))) |
8 | | - for(i in seq_len(npages)){ |
9 | | - from <- pagesize * (i-1) + 1; |
| 8 | + for (i in seq_len(npages)) { |
| 9 | + from <- pagesize * (i - 1) + 1 |
10 | 10 | to <- pagesize * i |
11 | | - out[[i]] <- FUN(x[from:to, ,drop = FALSE], ...) |
12 | | - if(verbose) cat("\rProcessed", i * pagesize, "rows...") |
| 11 | + out[[i]] <- FUN(x[from:to, , drop = FALSE], ...) |
| 12 | + if (verbose) cat("\rProcessed", i * pagesize, "rows...") |
13 | 13 | } |
14 | 14 |
|
15 | | - if(lastpage){ |
16 | | - from <- nr - lastpage + 1; |
17 | | - out[[npages + 1]] <- FUN(x[from:nr, ,drop = FALSE], ...) |
| 15 | + if (lastpage) { |
| 16 | + from <- nr - lastpage + 1 |
| 17 | + out[[npages + 1]] <- FUN(x[from:nr, , drop = FALSE], ...) |
18 | 18 | } |
19 | | - if(verbose) cat("\rComplete! Processed total of", nr, "rows.\n") |
| 19 | + if (verbose) cat("\rComplete! Processed total of", nr, "rows.\n") |
20 | 20 | out |
21 | 21 | } |
22 | 22 |
|
23 | 23 | #this is another slightly slower implementation |
24 | | -apply_by_pages2 <- function(x, FUN, pagesize, verbose, ...){ |
| 24 | +apply_by_pages2 <- function(x, FUN, pagesize, verbose, ...) { |
25 | 25 | x2 <- split(x, seq_len(nrow(x)) %/% pagesize) |
26 | | - for(page in x2){ |
27 | | - if(verbose) message("Writing ", nrow(page), " lines (", ").") |
| 26 | + for (page in x2) { |
| 27 | + if (verbose) message("Writing ", nrow(page), " lines (", ").") |
28 | 28 | FUN(page) |
29 | 29 | } |
30 | 30 | invisible() |
|
0 commit comments