aboutsummaryrefslogtreecommitdiff
path: root/R
diff options
context:
space:
mode:
authorFelix Cheung <felixcheung_m@hotmail.com>2016-06-15 10:29:07 -0700
committerShivaram Venkataraman <shivaram@cs.berkeley.edu>2016-06-15 10:29:07 -0700
commitd30b7e6696e20f1014c7f26aadbc051da0fac578 (patch)
tree820eb8cbcbcdc2dacaf0449c64ccad4a938065ba /R
parentde99c3d0813de8e8f83374a0a85a73f7386fdfb8 (diff)
downloadspark-d30b7e6696e20f1014c7f26aadbc051da0fac578.tar.gz
spark-d30b7e6696e20f1014c7f26aadbc051da0fac578.tar.bz2
spark-d30b7e6696e20f1014c7f26aadbc051da0fac578.zip
[SPARK-15637][SPARK-15931][SPARKR] Fix R masked functions checks
## What changes were proposed in this pull request? Because of the fix in SPARK-15684, this exclusion is no longer necessary. ## How was this patch tested? unit tests shivaram Author: Felix Cheung <felixcheung_m@hotmail.com> Closes #13636 from felixcheung/rendswith.
Diffstat (limited to 'R')
-rw-r--r--R/pkg/inst/tests/testthat/test_context.R27
1 files changed, 18 insertions, 9 deletions
diff --git a/R/pkg/inst/tests/testthat/test_context.R b/R/pkg/inst/tests/testthat/test_context.R
index 1d56ced399..126484c995 100644
--- a/R/pkg/inst/tests/testthat/test_context.R
+++ b/R/pkg/inst/tests/testthat/test_context.R
@@ -19,21 +19,26 @@ context("test functions in sparkR.R")
test_that("Check masked functions", {
# Check that we are not masking any new function from base, stats, testthat unexpectedly
- masked <- conflicts(detail = TRUE)$`package:SparkR`
- expect_true("describe" %in% masked) # only when with testthat..
- func <- lapply(masked, function(x) { capture.output(showMethods(x))[[1]] })
- funcSparkROrEmpty <- grepl("\\(package SparkR\\)$|^$", func)
- maskedBySparkR <- masked[funcSparkROrEmpty]
+ # NOTE: We should avoid adding entries to *namesOfMaskedCompletely* as masked functions make it
+ # hard for users to use base R functions. Please check when in doubt.
+ namesOfMaskedCompletely <- c("cov", "filter", "sample")
namesOfMasked <- c("describe", "cov", "filter", "lag", "na.omit", "predict", "sd", "var",
"colnames", "colnames<-", "intersect", "rank", "rbind", "sample", "subset",
"summary", "transform", "drop", "window", "as.data.frame")
- namesOfMaskedCompletely <- c("cov", "filter", "sample")
if (as.numeric(R.version$major) >= 3 && as.numeric(R.version$minor) >= 3) {
namesOfMasked <- c("endsWith", "startsWith", namesOfMasked)
- namesOfMaskedCompletely <- c("endsWith", "startsWith", namesOfMaskedCompletely)
}
+ masked <- conflicts(detail = TRUE)$`package:SparkR`
+ expect_true("describe" %in% masked) # only when with testthat..
+ func <- lapply(masked, function(x) { capture.output(showMethods(x))[[1]] })
+ funcSparkROrEmpty <- grepl("\\(package SparkR\\)$|^$", func)
+ maskedBySparkR <- masked[funcSparkROrEmpty]
expect_equal(length(maskedBySparkR), length(namesOfMasked))
- expect_equal(sort(maskedBySparkR), sort(namesOfMasked))
+ # make the 2 lists the same length so expect_equal will print their content
+ l <- max(length(maskedBySparkR), length(namesOfMasked))
+ length(maskedBySparkR) <- l
+ length(namesOfMasked) <- l
+ expect_equal(sort(maskedBySparkR, na.last = TRUE), sort(namesOfMasked, na.last = TRUE))
# above are those reported as masked when `library(SparkR)`
# note that many of these methods are still callable without base:: or stats:: prefix
# there should be a test for each of these, except followings, which are currently "broken"
@@ -42,7 +47,11 @@ test_that("Check masked functions", {
}))
maskedCompletely <- masked[!funcHasAny]
expect_equal(length(maskedCompletely), length(namesOfMaskedCompletely))
- expect_equal(sort(maskedCompletely), sort(namesOfMaskedCompletely))
+ l <- max(length(maskedCompletely), length(namesOfMaskedCompletely))
+ length(maskedCompletely) <- l
+ length(namesOfMaskedCompletely) <- l
+ expect_equal(sort(maskedCompletely, na.last = TRUE),
+ sort(namesOfMaskedCompletely, na.last = TRUE))
})
test_that("repeatedly starting and stopping SparkR", {