Skip to content

Commit f7c6830

Browse files
committed
Skip long tests on CRAN
1 parent 093fec1 commit f7c6830

5 files changed

Lines changed: 98 additions & 64 deletions

File tree

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ S3method(min,FileArray)
1515
S3method(range,FileArray)
1616
S3method(subset,FileArray)
1717
S3method(sum,FileArray)
18+
export(apply)
1819
export(filearray_bind)
1920
export(filearray_create)
2021
export(filearray_load)
@@ -26,6 +27,7 @@ export(fwhich)
2627
export(mapreduce)
2728
export(typeof)
2829
exportClasses(FileArray)
30+
exportMethods(apply)
2931
exportMethods(mapreduce)
3032
exportMethods(typeof)
3133
importFrom(Rcpp,sourceCpp)

R/methods.R

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -498,70 +498,70 @@ setMethod('typeof', signature(x = "FileArray"), function(x){
498498
#' @param ... optional arguments to \code{FUN}
499499
#' @param simplify a logical indicating whether results should be simplified if possible
500500
#' @return See Section 'Value' in \code{\link[base]{apply}};
501-
#' @noRd
502-
# setGeneric("apply")
501+
#' @export
502+
setGeneric("apply")
503503

504504
#' @rdname apply
505-
#' @noRd
506-
# setMethod(
507-
# 'apply', signature(X = "FileArray"),
508-
# function(X, MARGIN, FUN, ..., simplify = TRUE){
509-
# if(!X$valid()){
510-
# stop("Invalid file array")
511-
# }
512-
# dim <- X$dimension()
513-
#
514-
# FUN <- match.fun(FUN)
515-
# simplify <- isTRUE(simplify)
516-
# d <- dim(X)
517-
# dl <- length(d)
518-
# dn <- dimnames(X)
519-
# ds <- seq_len(dl)
520-
# if (is.character(MARGIN)) {
521-
# dnn <- names(dn)
522-
# if (is.null(dnn))
523-
# stop("'X' must have named dimnames")
524-
# MARGIN <- match(MARGIN, dnn)
525-
# if (anyNA(MARGIN))
526-
# stop("not all elements of 'MARGIN' are names of dimensions")
527-
# }
528-
# d.call <- d[-MARGIN]
529-
# d.ans <- d[MARGIN]
530-
# if (anyNA(d.call) || anyNA(d.ans)) {
531-
# stop("'MARGIN' does not match dim(X)")
532-
# }
533-
# s.call <- ds[-MARGIN]
534-
# s.ans <- ds[MARGIN]
535-
# if(length(s.ans) != 1){
536-
# stop("`apply` on FileArray margin size can only be 1.")
537-
# }
538-
# dn.call <- dn[-MARGIN]
539-
# dn.ans <- dn[MARGIN]
540-
# d2 <- prod(d.ans)
541-
# if (d2 == 0L) {
542-
# newX <- array(vector(typeof(X), 1L),
543-
# dim = c(prod(d.call), 1L))
544-
# if (length(d.call) < 2L) {
545-
# tmp <- newX[, 1]
546-
# } else {
547-
# tmp <- array(newX[, 1L], d.call, dn.call)
548-
# }
549-
# ans <- forceAndCall(1, FUN, tmp, ...)
550-
# if(is.null(ans)){
551-
# return(ans)
552-
# } else if (length(d.ans) < 2L) {
553-
# return(ans[1L][-1L])
554-
# } else {
555-
# return(array(ans, d.ans, dn.ans))
556-
# }
557-
# }
558-
#
559-
# tmp <- rep("", dl)
560-
# tmp[[s.ans]] <- ".__i__."
561-
# f <- sprintf("function(.__i__., ...){ FUN(X[%s], ...) }", paste(tmp, collapse = ","))
562-
# f <- eval(parse(text = f))
563-
#
564-
# sapply(seq_len(d[[s.ans]]), f, ..., simplify = simplify)
565-
# }
566-
# )
505+
#' @export
506+
setMethod(
507+
'apply', signature(X = "FileArray"),
508+
function(X, MARGIN, FUN, ..., simplify = TRUE){
509+
if(!X$valid()){
510+
stop("Invalid file array")
511+
}
512+
dim <- X$dimension()
513+
514+
FUN <- match.fun(FUN)
515+
simplify <- isTRUE(simplify)
516+
d <- dim(X)
517+
dl <- length(d)
518+
dn <- dimnames(X)
519+
ds <- seq_len(dl)
520+
if (is.character(MARGIN)) {
521+
dnn <- names(dn)
522+
if (is.null(dnn))
523+
stop("'X' must have named dimnames")
524+
MARGIN <- match(MARGIN, dnn)
525+
if (anyNA(MARGIN))
526+
stop("not all elements of 'MARGIN' are names of dimensions")
527+
}
528+
d.call <- d[-MARGIN]
529+
d.ans <- d[MARGIN]
530+
if (anyNA(d.call) || anyNA(d.ans)) {
531+
stop("'MARGIN' does not match dim(X)")
532+
}
533+
s.call <- ds[-MARGIN]
534+
s.ans <- ds[MARGIN]
535+
if(length(s.ans) != 1){
536+
stop("`apply` on FileArray margin size can only be 1.")
537+
}
538+
dn.call <- dn[-MARGIN]
539+
dn.ans <- dn[MARGIN]
540+
d2 <- prod(d.ans)
541+
if (d2 == 0L) {
542+
newX <- array(vector(typeof(X), 1L),
543+
dim = c(prod(d.call), 1L))
544+
if (length(d.call) < 2L) {
545+
tmp <- newX[, 1]
546+
} else {
547+
tmp <- array(newX[, 1L], d.call, dn.call)
548+
}
549+
ans <- forceAndCall(1, FUN, tmp, ...)
550+
if(is.null(ans)){
551+
return(ans)
552+
} else if (length(d.ans) < 2L) {
553+
return(ans[1L][-1L])
554+
} else {
555+
return(array(ans, d.ans, dn.ans))
556+
}
557+
}
558+
559+
tmp <- rep("", dl)
560+
tmp[[s.ans]] <- ".__i__."
561+
f <- sprintf("function(.__i__., ...){ FUN(X[%s], ...) }", paste(tmp, collapse = ","))
562+
f <- eval(parse(text = f))
563+
564+
sapply(seq_len(d[[s.ans]]), f, ..., simplify = simplify)
565+
}
566+
)
567567

filearray.Rproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ LaTeX: pdfLaTeX
1515
BuildType: Package
1616
PackageUseDevtools: Yes
1717
PackageInstallArgs: --no-multiarch --with-keep.source
18+
PackageCheckArgs: --as-cran
1819
PackageRoxygenize: rd,collate,namespace,vignette

man/apply.Rd

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-collapse.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ expect_equivalent_cplx <- function(x, y, eps = 1e-6){
8484
}
8585

8686
test_that("R/C++ - Collapse", {
87+
testthat::skip_on_cran()
8788
bsz <- get_buffer_size()
8889
on.exit({
8990
set_buffer_size(bsz)
@@ -194,6 +195,7 @@ test_that("R/C++ - Collapse", {
194195
})
195196

196197
test_that("R/C++ - Float", {
198+
testthat::skip_on_cran()
197199
bsz <- get_buffer_size()
198200
on.exit({
199201
set_buffer_size(bsz)
@@ -305,6 +307,7 @@ test_that("R/C++ - Float", {
305307
})
306308

307309
test_that("R/C++ - Collapse (complex)", {
310+
testthat::skip_on_cran()
308311
bsz <- get_buffer_size()
309312
on.exit({
310313
set_buffer_size(bsz)

0 commit comments

Comments
 (0)