[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [metrics-web/release] Avoid underscores in write_* function parameters.
commit 3f1cafdb5c4dffecbeab2a6688218d91f35c79ce
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Thu May 10 21:30:54 2018 +0200
Avoid underscores in write_* function parameters.
We added underscores to parameters in write_* functions when they
would otherwise conflict with columns in the processed data. For
example, if a graph supports a `country` parameter and the data also
contains a `country` column, dplyr/tidyr won't know which `country` we
mean. That's why we renamed the parameter to `country_`.
However, we're soon going to make parameters optional, and if R
receives a couple of parameters of which one has the name `country`,
it can't match that to its `country_` parameter. We need to change the
parameter back to `country` for this to work, which conflicts with the
issue we were fixing earlier.
Turns out there's a way to use the same name for parameter and data
column: whenever we want to use the parameter, we use the
quasiquotation operator `!!` which evaluates its argument early and
inlines the result; and whenever we want to refer to the data column,
we just refer to it by name, without that operator.
Prepares #25383.
---
src/main/R/rserver/graphs.R | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/main/R/rserver/graphs.R b/src/main/R/rserver/graphs.R
index 2ac2756..ebb8c80 100644
--- a/src/main/R/rserver/graphs.R
+++ b/src/main/R/rserver/graphs.R
@@ -629,14 +629,14 @@ plot_torperf <- function(start, end, source, server, filesize, path) {
# harder than for other functions, because plot_torperf uses different
# colours based on which sources exist, unrelated to which source is
# plotted. Left as future work.
-write_torperf <- function(start, end, source_, server_, filesize_, path) {
+write_torperf <- function(start, end, source, server, filesize, path) {
read.csv(paste(stats_dir, "torperf-1.1.csv", sep = ""),
colClasses = c("date" = "Date")) %>%
filter(date >= as.Date(start), date <= as.Date(end),
- filesize == ifelse(filesize_ == "50kb", 50 * 1024,
- ifelse(filesize_ == "1mb", 1024 * 1024, 5 * 1024 * 1024)),
- source == ifelse(source_ == "all", "", source_),
- server == server_) %>%
+ filesize == ifelse(!!filesize == "50kb", 50 * 1024,
+ ifelse(!!filesize == "1mb", 1024 * 1024, 5 * 1024 * 1024)),
+ source == ifelse(!!source == "all", "", !!source),
+ server == !!server) %>%
transmute(date, q1 = q1 / 1e3, md = md / 1e3, q3 = q3 / 1e3) %>%
write.csv(path, quote = FALSE, row.names = FALSE)
}
@@ -921,18 +921,18 @@ plot_userstats_bridge_version <- function(start, end, version, path) {
plot_userstats(start, end, "bridge", "version", version, "off", path)
}
-write_userstats_relay_country <- function(start, end, country_, events,
+write_userstats_relay_country <- function(start, end, country, events,
path) {
load(paste(rdata_dir, "clients-relay.RData", sep = ""))
u <- data %>%
filter(date >= as.Date(start), date <= as.Date(end),
- country == ifelse(country_ == "all", "", country_), transport == "",
+ country == ifelse(!!country == "all", "", !!country), transport == "",
version == "")
- if (country_ != "all" && events == "on") {
+ if (country != "all" && events == "on") {
u <- u %>%
mutate(downturns = clients < u$lower, upturns = clients > upper) %>%
select(date, clients, downturns, upturns, lower, upper)
- } else if (country_ != "all" && events != "off") {
+ } else if (country != "all" && events != "off") {
u <- u %>%
mutate(downturns = clients < u$lower, upturns = clients > upper) %>%
select(date, clients, downturns, upturns)
@@ -945,11 +945,11 @@ write_userstats_relay_country <- function(start, end, country_, events,
write.csv(path, quote = FALSE, row.names = FALSE)
}
-write_userstats_bridge_country <- function(start, end, country_, path) {
+write_userstats_bridge_country <- function(start, end, country, path) {
load(paste(rdata_dir, "clients-bridge.RData", sep = ""))
data %>%
filter(date >= as.Date(start), date <= as.Date(end),
- country == ifelse(country_ == "all", "", country_), transport == "",
+ country == ifelse(!!country == "all", "", !!country), transport == "",
version == "") %>%
select(date, clients) %>%
rename(users = clients) %>%
@@ -982,11 +982,11 @@ write_userstats_bridge_transport <- function(start, end, transports, path) {
write.csv(path, quote = FALSE, row.names = FALSE)
}
-write_userstats_bridge_version <- function(start, end, version_, path) {
+write_userstats_bridge_version <- function(start, end, version, path) {
load(paste(rdata_dir, "clients-bridge.RData", sep = ""))
data %>%
filter(date >= as.Date(start), date <= as.Date(end),
- country == "", transport == "", version == version_) %>%
+ country == "", transport == "", version == !!version) %>%
select(date, clients) %>%
rename(users = clients) %>%
write.csv(path, quote = FALSE, row.names = FALSE)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits