-
Notifications
You must be signed in to change notification settings - Fork 0
/
figure-iris-cols-data.R
75 lines (71 loc) · 2.33 KB
/
figure-iris-cols-data.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
source("packages.R")
iris.pattern.nc <- list(
"X",
before=".*",
"[.]",
column=".*",
"[.]",
dim=".*")
iris.pattern.args <- nc::var_args_list(iris.pattern.nc)
iris.reshape.cols <- iris[, 1:4]
names_to <- names(iris.pattern.args$fun.list)
names_to[names_to=="column"] <- ".value"
N.rep.vec <- as.integer(c(0, 10^seq(0, 4, by=0.5)))
timing.dt.list <- list()
for(N.rep in N.rep.vec){
print(N.rep)
i.vec <- 1:N.rep
L <- lapply(i.vec, function(i)iris.reshape.cols)
names(L) <- i.vec
L[["0"]] <- iris
some.iris <- do.call(data.frame, L)
N.col <- ncol(some.iris)
result.list <- list()
m.args <- list(
times=10,
control=list(order="block"),
"nc::capture_melt_multiple"=quote({
result.list[["nc"]] <- nc::capture_melt_multiple(
some.iris, iris.pattern.nc)
}),
"tidyr::pivot_longer"=quote({
result.list[["pivot"]] <- tidyr::pivot_longer(
some.iris,
grep(iris.pattern.args$pattern, names(some.iris)),
names_to=names_to,
names_pattern=iris.pattern.args$pattern)
}),
"data.table::melt"=quote({
result.list$dt <- data.table::melt.data.table(
data.table(some.iris),
measure.vars=patterns(Sepal="Sepal", Petal="Petal"))
}))
if(N.rep <= 10000){
m.args[["stats::reshape"]] <- quote({
new.names <- sub("(.*?)[.](.*)", "\\2_\\1", names(some.iris))
result.list$stats <- stats::reshape(
structure(some.iris, names=new.names),
direction="long",
varying=1:(ncol(some.iris)-1))
})
m.args[["cdata::rowrecs_to_blocks"]] <- quote({
part.list <- list()
for(part in c("Petal", "Sepal")){
part.list[[part]] <- grep(part, names(some.iris), value=TRUE)
}
controlTable.args <- c(list(
stringsAsFactors=FALSE,
dim=sub(".Sepal.", "", part.list$Sepal, fixed=TRUE)),
part.list)
controlTable <- do.call(data.frame, controlTable.args)
result.list$cdata <- cdata::rowrecs_to_blocks(
some.iris, controlTable=controlTable, columnsToCopy="X0.Species")
})
}
m.result <- do.call(microbenchmark, m.args)
timing.dt.list[[paste(N.rep)]] <- data.table(N.rep, N.col, m.result)
result.row.vec <- sapply(result.list, nrow)
stopifnot(result.row.vec[1] == result.row.vec)
}
timing.dt <- do.call(rbind, timing.dt.list)
saveRDS(timing.dt, "figure-iris-cols-data.rds")