Github user felixcheung commented on a diff in the pull request:
https://github.com/apache/spark/pull/19243#discussion_r139602407
--- Diff: R/pkg/R/DataFrame.R ---
@@ -998,33 +998,39 @@ setMethod("unique",
#' sparkR.session()
#' path <- "path/to/file.json"
#' df <- read.json(path)
+#' collect(sample(df, fraction=0.5))
#' collect(sample(df, FALSE, 0.5))
-#' collect(sample(df, TRUE, 0.5))
+#' collect(sample(df, TRUE, 0.5, seed=3))
#'}
#' @note sample since 1.4.0
setMethod("sample",
- signature(x = "SparkDataFrame", withReplacement = "logical",
- fraction = "numeric"),
- function(x, withReplacement, fraction, seed) {
- if (fraction < 0.0) stop(cat("Negative fraction value:",
fraction))
+ signature(x = "SparkDataFrame"),
+ function(x, withReplacement = FALSE, fraction, seed) {
+ if (!is.numeric(fraction)) {
+ stop(paste("fraction must be numeric; however, got",
class(fraction)))
+ }
+ if (!is.logical(withReplacement)) {
+ stop(paste("withReplacement must be logical; however, got",
class(withReplacement)))
+ }
if (!missing(seed)) {
# TODO : Figure out how to send integer as java.lang.Long to
JVM so
# we can send seed as an argument through callJMethod
- sdf <- callJMethod(x@sdf, "sample", withReplacement,
fraction, as.integer(seed))
+ sdf <- handledCallJMethod(x@sdf, "sample", withReplacement,
+ fraction, as.integer(seed))
--- End diff --
we should be careful only `as.integer` if it isn't NULL or NA
```
> as.integer(NULL)
integer(0)
> as.integer(NA)
[1] NA
```
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]