Permalink
Browse files

.n column in result of rdply is numeric again

Tests had to be altered, because this was actually the behavior of plyr 1.8.
  • Loading branch information...
Kirill Müller
Kirill Müller committed Feb 20, 2014
1 parent 68617ea commit 83e6361480e1ffde5ef4966e7665fd90eccb0ee2
Showing with 9 additions and 9 deletions.
  1. +6 −6 R/rdply.r
  2. +3 −3 inst/tests/test-rply.r
View
@@ -31,10 +31,10 @@ rdply <- function(.n, .expr, .progress = "none", .id = NA) {
res <- .rlply_worker(.n, .progress,
eval.parent(substitute(function() .expr)))
names(res) <- seq_len(.n)
- if (is.na(.id)) {
- .id <- ".n"
- id_as_factor <- FALSE
- } else
- id_as_factor <- TRUE
- list_to_dataframe(res, id_name = .id, id_as_factor = id_as_factor)
+ labels <- data.frame(.n = seq_len(.n))
+ if (!is.na(.id)) {
+ labels$.n <- factor(labels$.n, levels = labels$.n)
+ names(labels) <- .id
+ }
+ list_to_dataframe(res, labels)
}
View
@@ -113,7 +113,7 @@ test_that("Side effects for rdply", {
if (n == 0) {
exp_res <- data.frame()
} else {
- exp_res <- data.frame(.n = as.character(1L:n), i = 1L:n, stringsAsFactors = FALSE)
+ exp_res <- data.frame(.n = 1L:n, i = 1L:n, stringsAsFactors = FALSE)
}
i <- 0
@@ -140,7 +140,7 @@ test_that("Invalid arguments for r_ply", {
expect_error(r_ply(list(5), identity))
})
-test_that(".id columnd for rdply", {
- expect_equal(rdply(5, 10)$.n, as.character(1:5))
+test_that(".id column for rdply", {
+ expect_equal(rdply(5, 10)$.n, 1:5)
expect_equal(rdply(5, 10, .id=".n")$.n, factor(1:5))
})

0 comments on commit 83e6361

Please sign in to comment.