rapids/src/features/messages_features.R

21 lines
1.0 KiB
R
Raw Normal View History

2020-03-31 19:33:03 +02:00
# If you want to implement extra features, source(..) a new file and duplicate the line "features <- merge(...)", then
# swap base_sms_features(...) for your own function
2020-05-02 01:46:04 +02:00
source("renv/activate.R")
source("src/features/messages/messages_base.R")
2020-03-31 19:33:03 +02:00
library(dplyr, warn.conflicts = FALSE)
sms <- read.csv(snakemake@input[[1]])
day_segment <- snakemake@params[["day_segment"]]
requested_features <- snakemake@params[["features"]]
sms_type <- snakemake@params[["messages_type"]]
2020-03-31 19:33:03 +02:00
features <- data.frame(local_date = character(), stringsAsFactors = FALSE)
2020-03-31 19:33:03 +02:00
# Compute base SMS features
features <- merge(features, base_sms_features(sms, sms_type, day_segment, requested_features), by="local_date", all = TRUE)
if(ncol(features) != length(requested_features) + 1)
stop(paste0("The number of features in the output dataframe (=", ncol(features),") does not match the expected value (=", length(requested_features)," + 1). Verify your SMS feature extraction functions"))
write.csv(features, snakemake@output[[1]], row.names = FALSE)