| | library(rvest) |
| | library(dplyr) |
| | library(stringr) |
| | library(readr) |
| | library(httr) |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | get_jma_data <- function(block_no, year, month, day = NULL, prec_no, type = "s1", resolution = "Daily") { |
| | |
| | res_code <- "daily" |
| | if (resolution == "Hourly") res_code <- "hourly" |
| | if (resolution == "10 Minutes" || resolution == "10-Minute") res_code <- "10min" |
| | if (resolution == "Monthly") res_code <- "monthly" |
| |
|
| | |
| | if (resolution %in% c("Daily", "Monthly")) { |
| | url <- sprintf( |
| | "https://www.data.jma.go.jp/obd/stats/etrn/view/%s_%s.php?prec_no=%s&block_no=%s&year=%d&month=%d&day=&view=", |
| | res_code, type, prec_no, block_no, year, month |
| | ) |
| | } else { |
| | |
| | if (is.null(day)) { |
| | warning("Hourly/10-Minute resolution requires a day parameter") |
| | return(NULL) |
| | } |
| | url <- sprintf( |
| | "https://www.data.jma.go.jp/obd/stats/etrn/view/%s_%s.php?prec_no=%s&block_no=%s&year=%d&month=%d&day=%d&view=", |
| | res_code, type, prec_no, block_no, year, month, day |
| | ) |
| | } |
| |
|
| | message(sprintf("Downloading %s data from: %s", resolution, url)) |
| |
|
| | message(sprintf("Downloading %s data from: %s", resolution, url)) |
| | |
| | |
| | page <- tryCatch( |
| | { |
| | resp <- httr::GET(url, httr::timeout(10)) |
| | if (httr::status_code(resp) != 200) { |
| | warning(sprintf("Failed to download data: HTTP %s", httr::status_code(resp))) |
| | return(NULL) |
| | } |
| | read_html(resp) |
| | }, |
| | error = function(e) { |
| | warning("Failed to download data: ", e) |
| | return(NULL) |
| | } |
| | ) |
| |
|
| | if (is.null(page)) { |
| | return(NULL) |
| | } |
| |
|
| | |
| | tables <- html_table(page, fill = TRUE, header = FALSE) |
| | weather_table <- NULL |
| | min_rows <- ifelse(resolution == "Monthly", 10, 20) |
| | for (t in tables) { |
| | if (nrow(t) > min_rows && ncol(t) > 3) { |
| | weather_table <- t |
| | break |
| | } |
| | } |
| |
|
| | if (is.null(weather_table)) { |
| | return(NULL) |
| | } |
| | if (nrow(weather_table) <= 3) { |
| | return(NULL) |
| | } |
| |
|
| | if (nrow(weather_table) <= 3) { |
| | return(NULL) |
| | } |
| |
|
| | |
| | cols <- NULL |
| | col_names <- NULL |
| | time_col_name <- "Day" |
| | df <- NULL |
| |
|
| | |
| | |
| | if (resolution == "Monthly") { |
| | |
| | data_rows <- weather_table[2:nrow(weather_table), ] |
| | } else { |
| | data_rows <- weather_table[2:nrow(weather_table), ] |
| | } |
| |
|
| | |
| | |
| | header_row <- as.character(weather_table[1, ]) |
| | header_row_2 <- if (nrow(weather_table) >= 2) as.character(weather_table[2, ]) else rep("", length(header_row)) |
| | |
| | |
| | col_map <- list() |
| | col_indices <- c() |
| | col_final_names <- c() |
| | |
| | |
| | find_col <- function(p1, p2 = NULL) { |
| | i1 <- grep(p1, header_row) |
| | if (length(i1) == 0) return(NULL) |
| | |
| | if (is.null(p2)) return(i1[1]) |
| | |
| | |
| | matches <- i1[grep(p2, header_row_2[i1])] |
| | if (length(matches) > 0) return(matches[1]) |
| | return(NULL) |
| | } |
| |
|
| | |
| | if (resolution == "Monthly") { |
| | idx <- grep("月", header_row) |
| | if (length(idx) > 0) { col_indices <- c(col_indices, idx[1]); col_final_names <- c(col_final_names, "Month") } |
| | } else if (resolution == "Daily") { |
| | idx <- grep("^日", header_row) |
| | if (length(idx) > 0) { col_indices <- c(col_indices, idx[1]); col_final_names <- c(col_final_names, "Day") } |
| | } else if (resolution == "Hourly") { |
| | idx <- grep("^時", header_row) |
| | if (length(idx) > 0) { col_indices <- c(col_indices, idx[1]); col_final_names <- c(col_final_names, "Hour") } |
| | } else { |
| | idx <- grep("^時", header_row) |
| | if (length(idx) > 0) { col_indices <- c(col_indices, idx[1]); col_final_names <- c(col_final_names, "Time") } |
| | } |
| | |
| | |
| | if (resolution == "Monthly") { |
| | idx_sta <- find_col("気圧", "現地|平均") |
| | if (is.null(idx_sta)) { |
| | match <- grep("気圧", header_row) |
| | if (length(match) > 0) idx_sta <- match[1] |
| | } |
| | idx_sea <- find_col("気圧", "海面") |
| | if (is.null(idx_sea) && length(grep("気圧", header_row)) > 1) { |
| | match <- grep("気圧", header_row) |
| | idx_sea <- match[2] |
| | } |
| | if (!is.null(idx_sta)) { col_indices <- c(col_indices, idx_sta); col_final_names <- c(col_final_names, "Pressure") } |
| | if (!is.null(idx_sea)) { col_indices <- c(col_indices, idx_sea); col_final_names <- c(col_final_names, "Pressure_Sea_Level") } |
| | |
| | |
| | idx_pr <- find_col("降水量", "合計") |
| | if (is.null(idx_pr)) idx_pr <- grep("降水量", header_row)[1] |
| | if (!is.null(idx_pr)) { col_indices <- c(col_indices, idx_pr); col_final_names <- c(col_final_names, "Precipitation") } |
| | |
| | |
| | idx_tm <- find_col("気温", "平均") |
| | if (is.null(idx_tm)) idx_tm <- grep("気温", header_row)[1] |
| | idx_th <- find_col("気温", "最高") |
| | idx_tl <- find_col("気温", "最低") |
| | if (!is.null(idx_tm)) { col_indices <- c(col_indices, idx_tm); col_final_names <- c(col_final_names, "Temp_Mean") } |
| | if (!is.null(idx_th)) { col_indices <- c(col_indices, idx_th); col_final_names <- c(col_final_names, "Temp_Max") } |
| | if (!is.null(idx_tl)) { col_indices <- c(col_indices, idx_tl); col_final_names <- c(col_final_names, "Temp_Min") } |
| | |
| | |
| | idx_hm <- find_col("湿度", "平均") |
| | if (is.null(idx_hm)) idx_hm <- grep("湿度", header_row)[1] |
| | idx_hl <- find_col("湿度", "最小") |
| | if (!is.null(idx_hm)) { col_indices <- c(col_indices, idx_hm); col_final_names <- c(col_final_names, "Humidity") } |
| | if (!is.null(idx_hl)) { col_indices <- c(col_indices, idx_hl); col_final_names <- c(col_final_names, "Humidity_Min") } |
| | |
| | |
| | idx_ws <- find_col("風速", "平均風速|平均") |
| | if (is.null(idx_ws)) idx_ws <- grep("風速", header_row)[1] |
| | idx_ws_max <- find_col("風速", "最大風速") |
| | if (!is.null(idx_ws)) { col_indices <- c(col_indices, idx_ws); col_final_names <- c(col_final_names, "Wind_Speed") } |
| | if (!is.null(idx_ws_max)) { col_indices <- c(col_indices, idx_ws_max); col_final_names <- c(col_final_names, "Wind_Speed_Max") } |
| | |
| | } else if (resolution == "Daily") { |
| | |
| | id_p_sta <- find_col("気圧", "現地") |
| | if (is.null(id_p_sta)) id_p_sta <- grep("気圧", header_row)[1] |
| | id_p_sea <- find_col("気圧", "海面") |
| | if (is.null(id_p_sea) && length(grep("気圧", header_row)) > 1) { |
| | |
| | id_p_sea <- grep("気圧", header_row)[2] |
| | } |
| | if (!is.null(id_p_sta)) { col_indices <- c(col_indices, id_p_sta); col_final_names <- c(col_final_names, "Pressure") } |
| | if (!is.null(id_p_sea)) { col_indices <- c(col_indices, id_p_sea); col_final_names <- c(col_final_names, "Pressure_Sea_Level") } |
| |
|
| | |
| | id_pr_tot <- find_col("降水量", "合計") |
| | if (is.null(id_pr_tot)) id_pr_tot <- grep("降水量", header_row)[1] |
| | id_pr_1h <- find_col("降水量", "最大1時間") |
| | if (is.null(id_pr_1h) && length(grep("降水量", header_row)) >= 2) id_pr_1h <- grep("降水量", header_row)[2] |
| | id_pr_10m <- find_col("降水量", "最大10分") |
| | if (is.null(id_pr_10m) && length(grep("降水量", header_row)) >= 3) id_pr_10m <- grep("降水量", header_row)[3] |
| | |
| | if (!is.null(id_pr_tot)) { col_indices <- c(col_indices, id_pr_tot); col_final_names <- c(col_final_names, "Precipitation") } |
| | if (!is.null(id_pr_1h)) { col_indices <- c(col_indices, id_pr_1h); col_final_names <- c(col_final_names, "Precipitation_Max_1h") } |
| | if (!is.null(id_pr_10m)) { col_indices <- c(col_indices, id_pr_10m); col_final_names <- c(col_final_names, "Precipitation_Max_10min") } |
| |
|
| | |
| | |
| | temp_cols <- grep("気温", header_row) |
| | if (length(temp_cols) > 0) { |
| | |
| | id_tm <- find_col("気温", "平均") |
| | id_th <- find_col("気温", "最高") |
| | id_tl <- find_col("気温", "最低") |
| | |
| | |
| | if (is.null(id_tm) && length(temp_cols) >= 1) id_tm <- temp_cols[1] |
| | if (is.null(id_th) && length(temp_cols) >= 2) id_th <- temp_cols[2] |
| | if (is.null(id_tl) && length(temp_cols) >= 3) id_tl <- temp_cols[3] |
| | |
| | if (!is.null(id_tm)) { col_indices <- c(col_indices, id_tm); col_final_names <- c(col_final_names, "Temp_Mean") } |
| | if (!is.null(id_th)) { col_indices <- c(col_indices, id_th); col_final_names <- c(col_final_names, "Temp_Max") } |
| | if (!is.null(id_tl)) { col_indices <- c(col_indices, id_tl); col_final_names <- c(col_final_names, "Temp_Min") } |
| | } |
| | |
| | |
| | |
| | hum_cols <- grep("湿度", header_row) |
| | if (length(hum_cols) > 0) { |
| | id_hm <- find_col("湿度", "平均") |
| | id_hl <- find_col("湿度", "最小") |
| | |
| | if (is.null(id_hm) && length(hum_cols) >= 1) id_hm <- hum_cols[1] |
| | if (is.null(id_hl) && length(hum_cols) >= 2) id_hl <- hum_cols[2] |
| | |
| | if (!is.null(id_hm)) { col_indices <- c(col_indices, id_hm); col_final_names <- c(col_final_names, "Humidity") } |
| | if (!is.null(id_hl)) { col_indices <- c(col_indices, id_hl); col_final_names <- c(col_final_names, "Humidity_Min") } |
| | } |
| | |
| | |
| | |
| | wind_cols <- grep("風速", header_row) |
| | if (length(wind_cols) > 0) { |
| | id_ws <- find_col("風速", "平均風速") |
| | if (is.null(id_ws) && length(wind_cols) >= 1) id_ws <- wind_cols[1] |
| | |
| | id_ws_max <- find_col("風速", "最大風速") |
| | if (is.null(id_ws_max) && length(wind_cols) >= 2) id_ws_max <- wind_cols[2] |
| | |
| | id_ws_gust <- find_col("風速", "最大瞬間") |
| | if (is.null(id_ws_gust) && length(wind_cols) >= 4) id_ws_gust <- wind_cols[4] |
| | |
| | if (!is.null(id_ws)) { col_indices <- c(col_indices, id_ws); col_final_names <- c(col_final_names, "Wind_Speed") } |
| | if (!is.null(id_ws_max)) { col_indices <- c(col_indices, id_ws_max); col_final_names <- c(col_final_names, "Wind_Max_Speed") } |
| | if (!is.null(id_ws_gust)) { col_indices <- c(col_indices, id_ws_gust); col_final_names <- c(col_final_names, "Wind_Gust_Speed") } |
| | } |
| | |
| | } else { |
| | |
| | |
| | |
| | |
| | idx_sta <- find_col("気圧", "現地") |
| | if (is.null(idx_sta)) { |
| | |
| | match <- grep("気圧", header_row) |
| | |
| | if (length(match) > 0) idx_sta <- match[1] |
| | } |
| | |
| | idx_sea <- find_col("気圧", "海面") |
| | if (is.null(idx_sea) && length(grep("気圧", header_row)) > 1) { |
| | match <- grep("気圧", header_row) |
| | idx_sea <- match[2] |
| | } |
| | |
| | if (!is.null(idx_sta)) { col_indices <- c(col_indices, idx_sta); col_final_names <- c(col_final_names, "Pressure") } |
| | if (!is.null(idx_sea)) { col_indices <- c(col_indices, idx_sea); col_final_names <- c(col_final_names, "Pressure_Sea_Level") } |
| | |
| | |
| | idx_pr <- grep("降水量", header_row) |
| | if (length(idx_pr) > 0) { col_indices <- c(col_indices, idx_pr[1]); col_final_names <- c(col_final_names, "Precipitation") } |
| | |
| | |
| | idx_tm <- grep("気温", header_row) |
| | if (length(idx_tm) > 0) { col_indices <- c(col_indices, idx_tm[1]); col_final_names <- c(col_final_names, "Temperature") } |
| | |
| | |
| | idx_rh <- grep("湿度", header_row) |
| | if (length(idx_rh) > 0) { col_indices <- c(col_indices, idx_rh[1]); col_final_names <- c(col_final_names, "Humidity") } |
| |
|
| | |
| | |
| | idx <- find_col("風速", "風速") |
| | |
| | if (is.null(idx)) idx <- grep("風速", header_row)[1] |
| | |
| | if (!is.null(idx)) { |
| | col_indices <- c(col_indices, idx) |
| | col_final_names <- c(col_final_names, "Wind_Speed") |
| | } |
| | |
| | |
| | |
| | idx_dir <- find_col("風向", "風向") |
| | |
| | |
| | |
| | if (is.null(idx_dir)) { |
| | matches <- grep("風向", header_row) |
| | if (length(matches) > 0) idx_dir <- matches[length(matches)] |
| | } |
| | |
| | if (!is.null(idx_dir)) { |
| | col_indices <- c(col_indices, idx_dir) |
| | col_final_names <- c(col_final_names, "Wind_Direction") |
| | } |
| | } |
| |
|
| | |
| | idx <- grep("日照", header_row) |
| | if (length(idx) > 0) { |
| | col_indices <- c(col_indices, idx[1]) |
| | suffix <- if (resolution == "10 Minutes" || resolution == "10-Minute") "_Minutes" else "_Hours" |
| | col_final_names <- c(col_final_names, paste0("Sunshine", suffix)) |
| | } |
| | |
| | |
| | if (resolution == "Monthly") { |
| | idx_fall <- find_col("雪", "降雪") |
| | idx_depth <- find_col("雪", "最深積雪") |
| | idx_days <- grep("雪日数", header_row_2) |
| | |
| | if (!is.null(idx_fall)) { col_indices <- c(col_indices, idx_fall); col_final_names <- c(col_final_names, "Snowfall") } |
| | if (!is.null(idx_depth)) { col_indices <- c(col_indices, idx_depth); col_final_names <- c(col_final_names, "Snow_Depth") } |
| | if (length(idx_days) > 0) { col_indices <- c(col_indices, idx_days[1]); col_final_names <- c(col_final_names, "Snow_Days") } |
| | |
| | |
| | idx_fog <- grep("霧日数", header_row_2) |
| | if (length(idx_fog) > 0) { col_indices <- c(col_indices, idx_fog[1]); col_final_names <- c(col_final_names, "Fog_Days") } |
| | |
| | idx_thunder <- grep("雷日数", header_row_2) |
| | if (length(idx_thunder) > 0) { col_indices <- c(col_indices, idx_thunder[1]); col_final_names <- c(col_final_names, "Thunder_Days") } |
| | |
| | } else { |
| | |
| | |
| | idx_fall <- find_col("雪|降雪", "降雪") |
| | if (is.null(idx_fall)) idx_fall <- grep("降雪", header_row)[1] |
| | |
| | if (!is.null(idx_fall) && !is.na(idx_fall)) { |
| | col_indices <- c(col_indices, idx_fall) |
| | col_final_names <- c(col_final_names, "Snowfall") |
| | } |
| | |
| | idx_depth <- find_col("雪|積雪", "積雪") |
| | if (is.null(idx_depth)) idx_depth <- grep("積雪", header_row)[1] |
| | |
| | if (!is.null(idx_depth) && !is.na(idx_depth)) { |
| | col_indices <- c(col_indices, idx_depth) |
| | col_final_names <- c(col_final_names, "Snow_Depth") |
| | } |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | idx <- grep("露点温度", header_row) |
| | if (length(idx) > 0) { |
| | col_indices <- c(col_indices, idx[1]) |
| | col_final_names <- c(col_final_names, "Dew_Point") |
| | } |
| |
|
| | |
| | idx <- grep("蒸気圧", header_row) |
| | if (length(idx) > 0) { |
| | col_indices <- c(col_indices, idx[1]) |
| | col_final_names <- c(col_final_names, "Vapor_Pressure") |
| | } |
| |
|
| | |
| | idx <- grep("全天日射", header_row) |
| | if (length(idx) > 0) { |
| | col_indices <- c(col_indices, idx[1]) |
| | col_final_names <- c(col_final_names, "Solar_Radiation") |
| | } |
| |
|
| | |
| | idx <- grep("雲量", header_row) |
| | if (length(idx) > 0) { |
| | col_indices <- c(col_indices, idx[1]) |
| | col_final_names <- c(col_final_names, "Cloud_Cover") |
| | } |
| |
|
| | |
| | idx <- grep("視程", header_row) |
| | if (length(idx) > 0) { |
| | col_indices <- c(col_indices, idx[1]) |
| | col_final_names <- c(col_final_names, "Visibility") |
| | } |
| |
|
| | |
| | data_rows <- weather_table[2:nrow(weather_table), ] |
| | |
| | |
| | |
| | if (length(col_indices) > 0) { |
| | |
| | valid_mask <- !is.na(col_indices) |
| | col_indices <- col_indices[valid_mask] |
| | col_final_names <- col_final_names[valid_mask] |
| | |
| | |
| | |
| | |
| | dupe_mask <- !duplicated(col_indices) |
| | col_indices <- col_indices[dupe_mask] |
| | col_final_names <- col_final_names[dupe_mask] |
| | } |
| | |
| | if (length(col_indices) == 0) return(NULL) |
| | |
| | df <- data_rows[, col_indices, drop = FALSE] |
| | colnames(df) <- col_final_names |
| |
|
| | suppressWarnings({ |
| | clean_numeric <- function(x) { |
| | if (all(is.na(x))) { |
| | return(x) |
| | } |
| | x <- as.character(x) |
| | x <- str_remove_all(x, "[\\]\\)\\\\\\u00A0]") |
| | x[x == "///" | x == "--" | x == "" | x == "×" | x == "×"] <- NA |
| | as.numeric(x) |
| | } |
| |
|
| | |
| | if (resolution == "Monthly") { |
| | df$Month <- clean_numeric(df$Month) |
| | numeric_cols <- setdiff(names(df), "Month") |
| | for (col in numeric_cols) { |
| | df[[col]] <- clean_numeric(df[[col]]) |
| | } |
| | |
| | |
| | |
| | |
| | df <- df %>% |
| | filter(!is.na(Month)) %>% |
| | filter(Month == month) %>% |
| | mutate( |
| | Year = year, |
| | Date = as.Date(sprintf("%04d-%02d-01", Year, Month)) |
| | ) %>% |
| | select(Year, Month, everything()) |
| | } else if (resolution == "Daily") { |
| | df <- df %>% |
| | mutate( |
| | Year = year, |
| | Month = month, |
| | across(everything(), clean_numeric) |
| | ) %>% |
| | select(Year, Month, everything()) %>% |
| | filter(!is.na(Day)) |
| | } else { |
| | |
| | df <- df %>% |
| | mutate( |
| | Year = year, |
| | Month = month, |
| | Day = day |
| | ) |
| |
|
| | |
| | numeric_cols <- setdiff(names(df), c("Time", "Hour", "Year", "Month", "Day", "Wind_Direction")) |
| | for (col in numeric_cols) { |
| | df[[col]] <- clean_numeric(df[[col]]) |
| | } |
| | |
| | |
| | if ("Wind_Direction" %in% names(df)) { |
| | df$Wind_Direction <- as.character(df$Wind_Direction) |
| | df$Wind_Direction <- str_remove_all(df$Wind_Direction, "[\\]\\)\\\\\\u00A0]") |
| | df$Wind_Direction[df$Wind_Direction == "///" | df$Wind_Direction == "--" | df$Wind_Direction == "" | df$Wind_Direction == "×"] <- NA |
| | |
| | |
| | wind_dir_map <- c( |
| | "北" = 360, "N" = 360, |
| | "北北東" = 22.5, "NNE" = 22.5, |
| | "北東" = 45, "NE" = 45, |
| | "東北東" = 67.5, "ENE" = 67.5, |
| | "東" = 90, "E" = 90, |
| | "東南東" = 112.5, "ESE" = 112.5, |
| | "南東" = 135, "SE" = 135, |
| | "南南東" = 157.5, "SSE" = 157.5, |
| | "南" = 180, "S" = 180, |
| | "南南西" = 202.5, "SSW" = 202.5, |
| | "南西" = 225, "SW" = 225, |
| | "西南西" = 247.5, "WSW" = 247.5, |
| | "西" = 270, "W" = 270, |
| | "西北西" = 292.5, "WNW" = 292.5, |
| | "北西" = 315, "NW" = 315, |
| | "北北西" = 337.5, "NNW" = 337.5, |
| | "静穏" = NA, "Calm" = NA |
| | ) |
| | |
| | df$Wind_Direction_Deg <- wind_dir_map[df$Wind_Direction] |
| | } |
| |
|
| | |
| | if ("Hour" %in% names(df)) { |
| | |
| | df <- df %>% filter(Hour != "時") |
| | df$Hour <- as.numeric(as.character(df$Hour)) |
| | df <- df %>% filter(!is.na(Hour)) |
| | } |
| | |
| | |
| | if ("Time" %in% names(df)) { |
| | df <- df %>% filter(Time != "時分") |
| | } |
| |
|
| | |
| | df <- df %>% select(Year, Month, Day, everything()) |
| | } |
| | }) |
| |
|
| | return(df) |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | get_jma_range_data <- function(block_no, start_date, end_date, prec_no, type = "s1", resolution = "Daily") { |
| | results <- list() |
| |
|
| | if (resolution %in% c("Daily", "Monthly")) { |
| | |
| | dates <- seq(as.Date(format(start_date, "%Y-%m-01")), |
| | as.Date(format(end_date, "%Y-%m-01")), |
| | by = "month" |
| | ) |
| |
|
| | for (d in dates) { |
| | yr <- as.numeric(format(as.Date(d, origin = "1970-01-01"), "%Y")) |
| | mo <- as.numeric(format(as.Date(d, origin = "1970-01-01"), "%m")) |
| |
|
| | df <- get_jma_data(block_no, yr, mo, day = NULL, prec_no, type, resolution) |
| |
|
| | if (!is.null(df)) { |
| | if ("Date" %in% names(df)) { |
| | df_filtered <- df %>% |
| | filter(Date >= start_date & Date <= end_date) %>% |
| | select(-Date) |
| | } else if ("Day" %in% names(df)) { |
| | df_filtered <- df %>% |
| | mutate(Date = as.Date(sprintf("%04d-%02d-%02d", Year, Month, Day))) %>% |
| | filter(Date >= start_date & Date <= end_date) %>% |
| | select(-Date) |
| | } else { |
| | df_filtered <- df |
| | } |
| | results[[paste(yr, mo, sep = "_")]] <- df_filtered |
| | } |
| | Sys.sleep(0.1) |
| | } |
| | } else { |
| | |
| | all_days <- seq(start_date, end_date, by = "day") |
| |
|
| | for (d in all_days) { |
| | d_date <- as.Date(d, origin = "1970-01-01") |
| | yr <- as.numeric(format(d_date, "%Y")) |
| | mo <- as.numeric(format(d_date, "%m")) |
| | dy <- as.numeric(format(d_date, "%d")) |
| |
|
| | df <- get_jma_data(block_no, yr, mo, day = dy, prec_no, type, resolution) |
| |
|
| | if (!is.null(df)) { |
| | results[[paste(yr, mo, dy, sep = "_")]] <- df |
| | } |
| | Sys.sleep(0.1) |
| | } |
| | } |
| |
|
| | if (length(results) == 0) { |
| | return(NULL) |
| | } |
| | bind_rows(results) |
| | } |
| |
|