nathaneastwood / poorman

A poor man's dependency free grammar of data manipulation
https://nathaneastwood.github.io/poorman/
Other
340 stars 15 forks source link

Ensure `arrange()` works with list-columns, data.frame-columns and matrix-columns. #90

Open nathaneastwood opened 3 years ago

nathaneastwood commented 3 years ago

Arrange should be able to handle:

df <- structure(list(x = 1:3, y = list(3, 2, 1)), row.names = c(NA, -3L), class = "data.frame")
expect_equal(
  arrange(df, y),
  df,
  info = "arrange handles list columns: 1"
)
df <- structure(list(x = 1:3, y = list(sum, mean, sd)), row.names = c(NA, -3L), class = "data.frame")
expect_equal(
  arrange(df, y),
  df,
  info = "arrange handles list columns: 2"
)
df <- data.frame(x = 1:3)
df[, "y"] <- data.frame(z = 3:1)
expect_equal(
  arrange(df, y),
  {
    out <- data.frame(x = 3:1)
    out[, "y"] <- data.frame(z = 1:3)
    out
  },
  info = "arrange handles data.frame columns"
)
df <- data.frame(x = 1:3)
df[, "y"] <- matrix(6:1, ncol = 2)
expect_equal(
  arrange(df, y),
  df[3:1, ],
  info = "arrange handles matrix columns"
)