Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
simplified the impl of sample_frac
  • Loading branch information
gatorsmile committed Dec 7, 2015
commit 4337c35e03f8d70a6346e43888eaf3b6ba341722
6 changes: 2 additions & 4 deletions R/pkg/R/DataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,8 @@ setMethod("sample",
function(x, withReplacement, fraction, seed) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felixcheung Shouldn't we document this param in the roxygen doc above ? Otherwise how would anybody know we support a seed ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes we should add a @param seed above, thanks for catching it

if (fraction < 0.0) stop(cat("Negative fraction value:", fraction))
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))
} else {
sdf <- callJMethod(x@sdf, "sample", withReplacement, fraction)
Expand All @@ -695,11 +697,7 @@ setMethod("sample_frac",
signature(x = "DataFrame", withReplacement = "logical",
fraction = "numeric"),
function(x, withReplacement, fraction, seed) {
if (!missing(seed)) {
sample(x, withReplacement, fraction, as.integer(seed))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 space ident. directly pass seed is ok instead of as.integer(seed)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, done! This is my first time to read and write R. : ) Thank you!

} else {
sample(x, withReplacement, fraction)
}
})

#' nrow
Expand Down