|
|
|
|
|
library(dplyr) |
|
|
library(tibble) |
|
|
|
|
|
file <- "produkt_klima_tag_20240710_20260110_00011.txt" |
|
|
if (!file.exists(file)) unzip("debug_daily.zip", files = file) |
|
|
|
|
|
message("Reading table...") |
|
|
df <- read.table( |
|
|
file, |
|
|
sep = ";", |
|
|
header = TRUE, |
|
|
stringsAsFactors = FALSE, |
|
|
strip.white = TRUE, |
|
|
fill = TRUE |
|
|
) |
|
|
|
|
|
names(df) |
|
|
|
|
|
tryCatch( |
|
|
{ |
|
|
df <- df %>% |
|
|
rename_with(~ case_when( |
|
|
. == "TT_TU" ~ "temp", |
|
|
. == "RF_TU" ~ "rh", |
|
|
. == "R1" ~ "precip", |
|
|
. == "F" ~ "wind_speed", |
|
|
. == "D" ~ "wind_dir", |
|
|
. == "P" ~ "pressure", |
|
|
. == "P0" ~ "station_pressure", |
|
|
. %in% c("N_8", "V_N") ~ "cloud_cover", |
|
|
. %in% c("FX_10", "FX_911") ~ "wind_gust_max", |
|
|
. %in% c("FG_LBERG", "FG_STRAHL") ~ "solar_global", |
|
|
. %in% c("SD_LBERG", "SD_STRAHL", "SD_SO") ~ "sunshine_duration", |
|
|
|
|
|
|
|
|
. %in% c("TMK", "TM_K", "TNK", "TXK") ~ "temp", |
|
|
. %in% c("RSK", "RS_K") ~ "precip", |
|
|
. == "FM" ~ "wind_speed", |
|
|
. == "FX" ~ "wind_gust_max", |
|
|
. %in% c("SDK", "SD_SO") ~ "sunshine_duration", |
|
|
. == "UPM" ~ "rh", |
|
|
. == "PM" ~ "pressure", |
|
|
. == "NM" ~ "cloud_cover", |
|
|
TRUE ~ . |
|
|
)) |
|
|
|
|
|
message("Rename complete.") |
|
|
print(names(df)) |
|
|
}, |
|
|
error = function(e) { |
|
|
message("ERROR CAUGHT:") |
|
|
print(e) |
|
|
message("Message: ", conditionMessage(e)) |
|
|
} |
|
|
) |
|
|
|
|
|
file.remove(file) |
|
|
|