Skip to content

Commit 173ee82

Browse files
committed
drop dplyr and tidyr
1 parent 6edbd65 commit 173ee82

8 files changed

+78
-116
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ URL: http://r-simmer.org, https://github.com/r-simmer/simmer
2222
BugReports: https://github.com/r-simmer/simmer/issues
2323
Depends: R (>= 3.1.2)
2424
Imports: Rcpp, R6, magrittr, codetools, utils
25-
Suggests: simmer.plot, parallel, dplyr, tidyr, testthat, knitr, rmarkdown, rticles
25+
Suggests: simmer.plot, parallel, testthat, knitr, rmarkdown, rticles
2626
LinkingTo: Rcpp (>= 0.12.9), BH (>= 1.62.0-1)
2727
ByteCompile: yes
2828
RoxygenNote: 6.1.1

vignettes/simmer-02-jss.Rmd

+3-4
Original file line numberDiff line numberDiff line change
@@ -651,13 +651,12 @@ mm1.envs <- mclapply(1:100, function(i) {
651651

652652
With all these replicas, we could, for instance, perform a t-test over $N$, the average number of customers in the system:
653653

654-
```{r, mm1-replication-test, eval=requireNamespace("dplyr", quietly=TRUE)}
654+
```{r, mm1-replication-test}
655655
mm1.data <-
656656
get_mon_arrivals(mm1.envs) %>%
657-
dplyr::group_by(replication) %>%
658-
dplyr::summarise(mean = mean(end_time - start_time))
657+
aggregate(end_time - start_time ~ replication, data=., mean)
659658
660-
t.test(mm1.data[["mean"]])
659+
t.test(mm1.data[[2]])
661660
```
662661

663662
## Best practices

vignettes/simmer-04-bank-1.Rmd

+23-28
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ vignette: >
1414
```{r, cache = FALSE, include=FALSE}
1515
knitr::opts_chunk$set(collapse = T, comment = "#>",
1616
fig.width = 6, fig.height = 4, fig.align = "center")
17-
18-
required <- c("dplyr")
19-
20-
if (!all(sapply(required, requireNamespace, quietly = TRUE)))
21-
knitr::opts_chunk$set(eval = FALSE)
2217
```
2318

2419
## Introduction
@@ -64,7 +59,7 @@ bank <-
6459
add_generator("Customer", customer, at(5))
6560
6661
bank %>% run(until = 100)
67-
bank %>% get_mon_arrivals
62+
bank %>% get_mon_arrivals()
6863
```
6964

7065
The short trace printed out by the `get_mon_arrivals` function shows the result.
@@ -99,7 +94,7 @@ bank <-
9994
add_generator("Customer", customer, at(rexp(1, 1/5)))
10095
10196
bank %>% run(until = 100)
102-
bank %>% get_mon_arrivals
97+
bank %>% get_mon_arrivals()
10398
```
10499

105100
The trace shows that the customer now arrives at time 7.839305. Changing the
@@ -191,7 +186,7 @@ bank <-
191186
add_generator("Customer", customer, at(2, 5, 12))
192187
193188
bank %>% run(until = 400)
194-
bank %>% get_mon_arrivals
189+
bank %>% get_mon_arrivals()
195190
```
196191

197192
Alternatively, we can create three different customer trajectories for the three
@@ -233,7 +228,7 @@ bank <-
233228
add_generator("Evelyn", Evelyn, at(12))
234229
235230
bank %>% run(until = 400)
236-
bank %>% get_mon_arrivals
231+
bank %>% get_mon_arrivals()
237232
```
238233

239234
Again, the simulations finish before the 400 specified in the `run` function.
@@ -265,7 +260,7 @@ bank <-
265260
add_generator("Customer", customer, from_to(0, 41, function() {10}))
266261
267262
bank %>% run(until = 400)
268-
bank %>% get_mon_arrivals
263+
bank %>% get_mon_arrivals()
269264
```
270265

271266
### Many random customers
@@ -305,7 +300,7 @@ bank <-
305300
add_generator("Customer", customer, function() {c(0, rexp(4, 1/10), -1)})
306301
307302
bank %>% run(until = 400)
308-
bank %>% get_mon_arrivals
303+
bank %>% get_mon_arrivals()
309304
```
310305

311306
## A Service counter
@@ -336,7 +331,7 @@ step is complete, the `release` function causes the customer to make the counter
336331
available to other customers in the queue.
337332

338333
Since the activity trace does not produce the waiting time by default, this is
339-
calculated and appended using the `mutate` function in the dplyr package.
334+
calculated and appended using the `transform` function.
340335

341336
```{r, message = FALSE}
342337
library(simmer)
@@ -362,8 +357,8 @@ bank <-
362357
363358
bank %>% run(until = 400)
364359
bank %>%
365-
get_mon_arrivals %>%
366-
dplyr::mutate(waiting_time = end_time - start_time - activity_time)
360+
get_mon_arrivals() %>%
361+
transform(waiting_time = end_time - start_time - activity_time)
367362
```
368363

369364
Examining the trace we see that the first two customers get instant service but
@@ -404,8 +399,8 @@ bank <-
404399
405400
bank %>% run(until = 400)
406401
bank %>%
407-
get_mon_arrivals %>%
408-
dplyr::mutate(waiting_time = end_time - start_time - activity_time)
402+
get_mon_arrivals() %>%
403+
transform(waiting_time = end_time - start_time - activity_time)
409404
```
410405

411406
This model with random arrivals and exponential service times is an example of
@@ -453,8 +448,8 @@ bank <-
453448
454449
bank %>% run(until = 400)
455450
bank %>%
456-
get_mon_arrivals %>%
457-
dplyr::mutate(waiting_time = end_time - start_time - activity_time)
451+
get_mon_arrivals() %>%
452+
transform(waiting_time = end_time - start_time - activity_time)
458453
```
459454

460455
The waiting times in this model are much shorter than those for the single
@@ -499,12 +494,12 @@ bank <-
499494
500495
bank %>% run(until = 400)
501496
bank %>%
502-
get_mon_arrivals %>%
503-
dplyr::mutate(service_start_time = end_time - activity_time) %>%
504-
dplyr::arrange(start_time)
497+
get_mon_arrivals() %>%
498+
transform(service_start_time = end_time - activity_time) %>%
499+
.[order(.$start_time),]
505500
bank %>%
506-
get_mon_resources %>%
507-
dplyr::arrange(time)
501+
get_mon_resources() %>%
502+
.[order(.$time),]
508503
```
509504

510505
The results show that the customers chose the counter with the smallest number.
@@ -519,7 +514,7 @@ We now demonstrate how to calculate average waiting times for our customers. In
519514
the original SimPy version of this tutorial, this involved using 'Monitors'. In
520515
simmer, data is returned by the `get_mon_*` family of functions, as has already
521516
been demonstrated. Here, we simply summarise the data frame returned by the
522-
`get_mon_arrivals` function, using functions from the `dplyr` package.
517+
`get_mon_arrivals` function, using standard R functions.
523518

524519
We also increase the number of customers to 50 (find the number '49' in the
525520
code.code).
@@ -544,8 +539,8 @@ bank %>% run(until = 1000)
544539
545540
result <-
546541
bank %>%
547-
get_mon_arrivals %>%
548-
dplyr::mutate(waiting_time = end_time - start_time - activity_time)
542+
get_mon_arrivals() %>%
543+
transform(waiting_time = end_time - start_time - activity_time)
549544
```
550545

551546
The average waiting time for 50 customers in this 2-counter system is more
@@ -594,8 +589,8 @@ mclapply(c(393943, 100005, 777999555, 319999772), function(the_seed) {
594589
bank %>% run(until = 400)
595590
result <-
596591
bank %>%
597-
get_mon_arrivals %>%
598-
dplyr::mutate(waiting_time = end_time - start_time - activity_time)
592+
get_mon_arrivals() %>%
593+
transform(waiting_time = end_time - start_time - activity_time)
599594
paste("Average wait for ", sum(result$finished), " completions was ",
600595
mean(result$waiting_time), "minutes.")
601596
}) %>% unlist()

vignettes/simmer-04-bank-2.Rmd

+18-23
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ vignette: >
1515
knitr::opts_chunk$set(collapse = T, comment = "#>",
1616
fig.width = 6, fig.height = 4, fig.align = "center")
1717
18-
required <- c("simmer.plot", "dplyr")
18+
required <- c("simmer.plot")
1919
2020
if (!all(sapply(required, requireNamespace, quietly = TRUE)))
2121
knitr::opts_chunk$set(eval = FALSE)
@@ -55,7 +55,7 @@ priority of 0, we create and activate one special customer, Guido, with priority
5555
1 who arrives at time 23. This is to ensure that he arrives after Customer2.
5656

5757
Since the activity trace does not produce the waiting time by default, this is
58-
calculated and appended using the `mutate` function in the dplyr package.
58+
calculated and appended using the `transform` function.
5959

6060
```{r, message = FALSE}
6161
library(simmer)
@@ -84,8 +84,8 @@ bank <-
8484
8585
bank %>% run(until = 400)
8686
bank %>%
87-
get_mon_arrivals %>%
88-
dplyr::mutate(waiting_time = end_time - start_time - activity_time)
87+
get_mon_arrivals() %>%
88+
transform(waiting_time = end_time - start_time - activity_time)
8989
```
9090

9191
The output above displays the number of customers in the queue just as each one
@@ -131,8 +131,8 @@ bank <-
131131
132132
bank %>% run(until = 400)
133133
bank %>%
134-
get_mon_arrivals %>%
135-
dplyr::mutate(waiting_time = end_time - start_time - activity_time)
134+
get_mon_arrivals() %>%
135+
transform(waiting_time = end_time - start_time - activity_time)
136136
```
137137

138138
Though Guido arrives at the same time, 23, he no longer has to wait and
@@ -380,16 +380,11 @@ bank <- simmer()
380380
381381
customer <-
382382
trajectory("Customer's path") %>%
383-
log_(function() {
384-
capacity <-
385-
get_mon_resources(bank) %>%
386-
dplyr::filter(resource == "door") %>%
387-
.$capacity
388-
if (length(capacity) == 0 || tail(capacity, 1) == 0) {
389-
return("Here I am but the door is shut.")
390-
}
391-
"Here I am and the door is open."
392-
}) %>%
383+
log_(function()
384+
if (get_capacity(bank, "door") == 0)
385+
"Here I am but the door is shut."
386+
else "Here I am and the door is open."
387+
) %>%
393388
seize("door") %>%
394389
log_("I can go in!") %>%
395390
release("door") %>%
@@ -417,8 +412,8 @@ bank <-
417412
418413
bank %>% run(until = maxTime)
419414
bank %>%
420-
get_mon_arrivals %>%
421-
dplyr::mutate(waiting_time = end_time - start_time - activity_time)
415+
get_mon_arrivals() %>%
416+
transform(waiting_time = end_time - start_time - activity_time)
422417
```
423418

424419
The output above programs shows how the first two customers have to wait until
@@ -482,8 +477,8 @@ bank %>%
482477
483478
bank %>% run(until = maxTime)
484479
bank %>%
485-
get_mon_arrivals %>%
486-
dplyr::mutate(waiting_time = end_time - start_time - activity_time)
480+
get_mon_arrivals() %>%
481+
transform(waiting_time = end_time - start_time - activity_time)
487482
```
488483

489484
The output run for this program shows how the first two customers have to wait
@@ -535,8 +530,8 @@ bank %>%
535530
536531
bank %>% run(until = maxTime)
537532
bank %>%
538-
get_mon_arrivals %>%
539-
dplyr::mutate(waiting_time = end_time - start_time - activity_time)
533+
get_mon_arrivals() %>%
534+
transform(waiting_time = end_time - start_time - activity_time)
540535
```
541536

542537
This second method gives the same output as the first.
@@ -641,7 +636,7 @@ bank <-
641636
bank %>% run(until = 400)
642637
customer_monitor <-
643638
get_mon_arrivals(bank) %>%
644-
dplyr::mutate(wait = end_time - start_time - activity_time)
639+
transform(wait = end_time - start_time - activity_time)
645640
mean_waiting_time <- mean(customer_monitor$wait)
646641
647642
resource_monitor <- get_mon_resources(bank)

vignettes/simmer-05-simpy.Rmd

+10-22
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ vignette: >
1414
```{r, cache = FALSE, include=FALSE}
1515
knitr::opts_chunk$set(collapse = T, comment = "#>",
1616
fig.width = 6, fig.height = 4, fig.align = "center")
17-
18-
required <- c("dplyr")
19-
20-
if (!all(sapply(required, requireNamespace, quietly = TRUE)))
21-
knitr::opts_chunk$set(eval = FALSE)
2217
```
2318

2419
## Introduction
@@ -118,7 +113,6 @@ The `make_parts` trajectory defines a machine's operating loop. A worker seizes
118113
```{r, message=FALSE, warning=FALSE}
119114
make_parts <- function(machine)
120115
trajectory() %>%
121-
set_attribute("parts", 0) %>%
122116
seize(machine, 1) %>%
123117
timeout(function() rnorm(1, PT_MEAN, PT_SIGMA)) %>%
124118
set_attribute("parts", 1, mod="+") %>%
@@ -178,10 +172,7 @@ env %>%
178172
The last value per worker from the attributes table reports the number of parts made:
179173

180174
```{r, message=FALSE, warning=FALSE}
181-
get_mon_attributes(env) %>%
182-
dplyr::group_by(name) %>%
183-
dplyr::slice(n()) %>%
184-
dplyr::arrange(name)
175+
aggregate(value ~ name, get_mon_attributes(env), max)
185176
```
186177

187178
## Movie Renege
@@ -287,28 +278,25 @@ env %>%
287278
run(SIM_TIME)
288279
```
289280

290-
The analysis is performed with the help of `dplyr`:
281+
The analysis is performed with standard R tools:
291282

292283
```{r, message=FALSE, warning=FALSE}
293284
# get the three rows with the sold out instants
294285
sold_time <- get_mon_resources(env) %>%
295-
dplyr::filter(resource != "counter" & capacity == 0)
286+
subset(resource != "counter" & capacity == 0)
296287
297288
# get the arrivals that left at the sold out instants
298289
# count the number of arrivals per movie
299-
n_reneges <- dplyr::left_join(
300-
get_mon_arrivals(env) %>%
301-
dplyr::filter(finished == FALSE & end_time %in% sold_time$time),
302-
get_mon_attributes(env)
303-
) %>%
304-
dplyr::mutate(resource = movies[value]) %>%
305-
dplyr::group_by(resource) %>%
306-
dplyr::count()
290+
n_reneges <- get_mon_arrivals(env) %>%
291+
subset(finished == FALSE & end_time %in% sold_time$time) %>%
292+
merge(get_mon_attributes(env)) %>%
293+
transform(resource = movies[value]) %>%
294+
aggregate(value ~ resource, data=., length)
307295
308296
# merge the info and print
309-
invisible(apply(dplyr::left_join(sold_time, n_reneges), 1, function(i) {
297+
invisible(apply(merge(sold_time, n_reneges), 1, function(i) {
310298
cat("Movie '", i["resource"], "' was sold out in ", i["time"], " minutes.\n",
311-
" Number of people that left the queue: ", i["n"], "\n", sep="")
299+
" Number of people that left the queue: ", i["value"], "\n", sep="")
312300
}))
313301
```
314302

0 commit comments

Comments
 (0)