Skip to content
Closed
11 changes: 7 additions & 4 deletions tests/testthat/helper-plot-data.r
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
library(data.table)
# Transform the data as the coordinate system does
cdata <- function(plot) {
pieces <- ggplot_build(plot)

lapply(pieces$data, function(d) {
plyr::ddply(d, "PANEL", function(panel_data) {
scales <- panel_scales(pieces$panel, panel_data$PANEL[1])
d <- as.data.table(d)
d[, {
scales <- panel_scales(pieces$panel, .SD$PANEL[1])
details <- plot$coordinates$train(scales)
plot$coordinates$transform(panel_data, details)
})
transformed_data <- plot$coordinates$transform(.SD, details)
transformed_data
}, by = .(PANEL)]
})
}

Expand Down
12 changes: 8 additions & 4 deletions tests/testthat/test-compiler-animation.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
library(data.table)
acontext("animation")

if(require(maps) && require(plyr)){
if(require(maps)){
data(UStornadoes, package = "animint2")
stateOrder <- data.frame(state = unique(UStornadoes$state)[order(unique(UStornadoes$TornadoesSqMile), decreasing=T)], rank = 1:49) # order states by tornadoes per square mile
UStornadoes$state <- factor(UStornadoes$state, levels=stateOrder$state, ordered=TRUE)
UStornadoes$weight <- 1/UStornadoes$LandArea
# useful for stat_bin, etc.
USpolygons <- map_data("state")
USpolygons$state = state.abb[match(USpolygons$region, tolower(state.name))]
UStornadoCounts <-
ddply(UStornadoes, .(state, year), summarize, count=length(state))
USpolygons$state <- state.abb[match(USpolygons$region, tolower(state.name))]

# Convert to data.table
setDT(UStornadoes)
UStornadoCounts <- UStornadoes[, .(count = .N), by = .(state, year)]

tornado.anim <- list(
map=ggplot()+
geom_polygon(aes(
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-compiler-fortify.r
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
context("Fortify")
library(sp)
library(ggplot2)
library(dplyr)

test_that("Spatial polygons have correct ordering", {
make_square <- function(x = 0, y = 0, height = 1, width = 1){
Expand Down Expand Up @@ -32,6 +34,5 @@ test_that("Spatial polygons have correct ordering", {
polys2_sp <- SpatialPolygons(polys2)
fake_sp2 <- SpatialPolygonsDataFrame(polys2_sp, fake_data)

expect_equivalent(fortify(fake_sp), plyr::arrange(fortify(fake_sp2), id, order))

expect_equivalent(fortify(fake_sp), arrange(fortify(fake_sp2), id, order))
})
16 changes: 8 additions & 8 deletions tests/testthat/test-compiler-save-separate-chunks.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
acontext("save separate chunks")
library(plyr)
library(data.table)

data(FluView, package = "animint2")
# use one season to test
Expand Down Expand Up @@ -85,15 +85,15 @@ test_that("save separate chunks for geom_polygon", {
})

### test case 2
USdots <-
ddply(FluView$USpolygons, .(region), summarise,
mean.lat = mean(lat),
mean.long = mean(long))
# add state flu to points.
flu.points <- ldply(unique(state_flu$WEEKEND), function(we) {
# Convert plyr::ddply to data.table
USpolygons_dt <- as.data.table(FluView$USpolygons)
USdots <- USpolygons_dt[, .(mean.lat = mean(lat), mean.long = mean(long)), by = region]

# Convert plyr::ldply to data.table
flu.points <- rbindlist(lapply(unique(state_flu$WEEKEND), function(we) {
df <- subset(state_flu, WEEKEND == we)
merge(USdots, df, by.x = "region", by.y = "state")
})
}))

test_that("save separate chunks for geom_point without specifying group", {
# the compiler will not break a geom into chunks if any of the resulting
Expand Down
11 changes: 8 additions & 3 deletions tests/testthat/test-renderer1-hjust-text-anchor.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ grad.desc <- function(
dat <- grad.desc()
contour <- dat$contour
objective <- dat$objective
objective <- plyr::ldply(objective$iteration, function(i) {
df <- subset(objective, iteration <= i)

# Replaced plyr::ldply with data.table
library(data.table)
objective_dt <- as.data.table(objective)
objective <- objective_dt[, {
df <- .SD[iteration <= i]
cbind(df, iteration2 = i)
})
}, by = .(iteration)]

objective2 <- subset(objective, iteration == iteration2)

grad.desc.viz <- function(hjust) {
Expand Down
9 changes: 6 additions & 3 deletions tests/testthat/test-renderer1-interactivity.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,12 @@ UStornadoes$state <- factor(UStornadoes$state, levels=stateOrder$state, ordered=
UStornadoes$weight <- 1/UStornadoes$LandArea
USpolygons <- map_data("state")
USpolygons$state = state.abb[match(USpolygons$region, tolower(state.name))]
library(plyr)
UStornadoCounts <-
ddply(UStornadoes, .(state, year), summarize, count=length(state))

# Replaced plyr::ddply with data.table
library(data.table)
UStornadoes_dt <- as.data.table(UStornadoes)
UStornadoCounts <- UStornadoes_dt[, .(count = .N), by = .(state, year)]

seg.color <- "#55B1F7"
tornado.lines <- list(
map=ggplot()+
Expand Down
Loading