-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.R
31 lines (28 loc) · 990 Bytes
/
functions.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
write_pipeline <- function(removed_indexes) {
tar_helper("./_targets.R",
code = {
library(targets)
library(tarchetypes)
tar_option_set(packages = c("dplyr"))
source("functions.R")
list(
tar_target(data_file, "data/AirQualityUCI.csv", format = "file"),
tar_target(raw_data, read_data(data_file)),
tar_target(processed_data, clean_data(raw_data, !!removed_indexes))
)
}
)
}
clean_data <- function(data, removed_indexes = NULL) {
if(is.null(removed_indexes)) out <- data
removed_columns <- colnames(data)[removed_indexes]
out <- data %>% select(-all_of(removed_columns))
}
read_data <- function(path) {
read.csv(path)
}
plot_hist <- function(data, var) {
data %>% plot_ly(x = as.formula(glue("~{var}")), type = "histogram",
name = var) %>%
layout(title = glue("Histogram of {var}"))
}