diff --git a/DESCRIPTION b/DESCRIPTION index fdff3158..f1182a8b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,7 +27,7 @@ License: MIT + file LICENSE Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.0 +RoxygenNote: 7.3.2 Depends: R (>= 4.0.0) Imports: diff --git a/NAMESPACE b/NAMESPACE index cc46cf0a..a9cb5574 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ export(hydro_imgw) export(hydro_imgw_annual) export(hydro_imgw_daily) export(hydro_imgw_monthly) +export(hydro_shortening_imgw) export(meteo_imgw) export(meteo_imgw_daily) export(meteo_imgw_datastore) @@ -13,6 +14,7 @@ export(meteo_imgw_monthly) export(meteo_noaa_co2) export(meteo_noaa_hourly) export(meteo_ogimet) +export(meteo_shortening_imgw) export(nearest_stations_imgw) export(nearest_stations_noaa) export(nearest_stations_ogimet) diff --git a/NEWS.md b/NEWS.md index eec8e9fd..d32dc4b1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# climate 1.2.2 + +* Major fixes for adjusting code to stay in line with CRAN policies +* Fixes for `hydro_imgw()` set of functions due to changes in encoding and metadata structure + + # climate 1.2.1 * Corrected duplicated column names for IMGW-PIB stations diff --git a/R/check_locale.R b/R/check_locale.R index 25532845..1a5a552e 100644 --- a/R/check_locale.R +++ b/R/check_locale.R @@ -6,6 +6,8 @@ #' in the Polish metservice's repository and therefore will be forced to #' use ASCII//TRANSLIT #' @noRd +#' @keywords internal +#' @return 1 if the locale is not UTF-8, 0 otherwise check_locale = function() { diff --git a/R/clean_metadata_hydro.R b/R/clean_metadata_hydro.R index 7f6da71d..dda531cc 100644 --- a/R/clean_metadata_hydro.R +++ b/R/clean_metadata_hydro.R @@ -5,38 +5,36 @@ #' @param interval temporal interval #' @importFrom utils read.fwf #' @keywords internal +#' @noRd + clean_metadata_hydro = function(address, interval) { temp = tempfile() test_url(link = address, output = temp) - a = readLines(temp, warn = FALSE) - - a = iconv(a, from = "cp1250", to = "ASCII//TRANSLIT") # remove polish characters - a = gsub(a, pattern = "\\?", replacement = "") # removing extra characters after conversion - - # additional workarounds for mac os but not only... + a = read.csv(temp, header = FALSE, stringsAsFactors = FALSE, + fileEncoding = "CP1250", skip = 1, sep = "\t")$V1 + a = gsub(a, pattern = "\\?", replacement = "") a = gsub(x = a, pattern = "'", replacement = "") - a = gsub(x = a, pattern = "\\^", replacement = "") + a = trimws(gsub(x = a, pattern = "\\^", replacement = "")) + a = gsub(a, pattern = "\\s+", replacement = " ") if (interval == "monthly") { - b = list(data.frame(parameters = a[3:12])) # sklad danych jeszcze nie wiem jak ominąć problem kontroli - # ale on może się zmienić nie wiem czy nie lepiej wykluczyć ostatni rok + b = list(data.frame(parameters = a[1:10])) } if (interval == "daily") { - b = data.frame(parameters = a[3:12]) + b = data.frame(parameters = a[1:10]) } if (interval == "semiannual_and_annual") { - godzina = paste0(a[15], ":", a[16]) # nie jestem pewien czy tak bo w dokumentacji jest podzial na dwie kolumny, - #ale w pliku jest jedna kolumna a pomiaru brak - data = c(a[12:14], godzina) + godzina = paste0(a[13], ":", a[14]) + data = c(a[10:12], godzina) data_od = paste0("wystapienie_od_", data) - data_do = paste0("wystapienie_od_", data) - SPT = unlist(strsplit(a[10], "]/")) # stan/przeplyw/temperatura + data_do = paste0("wystapienie_do_", data) + SPT = unlist(strsplit(a[8], "]/")) # stan/przeplyw/temperatura SPT[1] = paste0(SPT[1], "]") SPT[2] = paste0(SPT[2], "]") b = NULL for (i in seq_along(SPT)) { - tmp = c(a[3:9], SPT[i], data_od, data_do) + tmp = c(a[1:7], SPT[i], data_od, data_do) b = cbind(b, tmp) } b = list("H" = data.frame(parameters = b[, 1]), diff --git a/R/clean_metadata_meteo.R b/R/clean_metadata_meteo.R index d721b2ef..7a5aac99 100644 --- a/R/clean_metadata_meteo.R +++ b/R/clean_metadata_meteo.R @@ -8,16 +8,12 @@ #' @importFrom stats na.omit #' @importFrom stringi stri_trans_general #' @keywords internal -#' +#' @noRd clean_metadata_meteo = function(address, rank = "synop", interval = "hourly") { temp = tempfile() test_url(link = address, output = temp) - - # a = readLines(temp, warn = FALSE, encoding = "CP1250") # doesn't work on mac, - # thus: - # a = iconv(a, from = "CP1250", to = "ASCII//TRANSLIT") a = read.csv(temp, header = FALSE, stringsAsFactors = FALSE, fileEncoding = "CP1250")$V1 a = gsub(a, pattern = "\\?", replacement = "") @@ -27,9 +23,6 @@ clean_metadata_meteo = function(address, rank = "synop", interval = "hourly") { a = gsub(x = a, pattern = "'", replacement = "") a = gsub(x = a, pattern = "\\^0", replacement = "") a = data.frame(V1 = a[nchar(a) > 3], stringsAsFactors = FALSE) - # this one does not work on windows - # a = suppressWarnings(na.omit(read.fwf(address, widths = c(1000), - # fileEncoding = "CP1250", stringsAsFactors = FALSE))) length_char = max(nchar(a$V1), na.rm = TRUE) if (rank == "precip" && interval == "hourly") length_char = 40 # exception for precip / hourly diff --git a/R/co2_demo.R b/R/co2_demo.R index 16272752..b1f71d76 100644 --- a/R/co2_demo.R +++ b/R/co2_demo.R @@ -6,7 +6,7 @@ #' #' @docType data #' @keywords datasets meteo -#' @examples +#' @returns data.frame with historical CO2 concentrations #' data(co2_demo) #' head(co2_demo) "co2_demo" diff --git a/R/get_coord_from_string.R b/R/get_coord_from_string.R index 985d1947..67714e6e 100644 --- a/R/get_coord_from_string.R +++ b/R/get_coord_from_string.R @@ -7,13 +7,8 @@ #' @format The returned object is the geographic coordinates using WGS84 (EPSG:4326) in decimal format. #' Negative values mean western or southern Hemisphere #' @keywords internal -#' -#' @examples -#' \donttest{ -#' txt = "12120: Leba (Poland)\nLatitude: 54-45N Longitude: 017-32E Altitude: 2 m." -#' climate:::get_coord_from_string(txt, pattern = "Latitude") -#' } -#' +#' @noRd + get_coord_from_string = function(txt, pattern = "Longitude") { tt = gregexpr(pattern, txt) start = tt[[1]][1] + attributes(tt[[1]])$match.length + 1 diff --git a/R/hydro_imgw.R b/R/hydro_imgw.R index b3670e40..5cc0ffb9 100644 --- a/R/hydro_imgw.R +++ b/R/hydro_imgw.R @@ -21,7 +21,7 @@ #' @return A data.frame with columns describing the hydrological parameters #' (e.g. flow, water level) where each row represent a measurement, #' depending on the interval, at a given hour, month or year. -#' If `coords = TRUE` additional two columns with geografic coordinates are added. +#' If `coords = TRUE` additional two columns with geographic coordinates are added. #' @examples #' \donttest{ #' x = hydro_imgw("monthly", year = 1999) diff --git a/R/hydro_imgw_annual.R b/R/hydro_imgw_annual.R index 7e36b2d1..5557792b 100644 --- a/R/hydro_imgw_annual.R +++ b/R/hydro_imgw_annual.R @@ -18,6 +18,7 @@ #' @importFrom utils download.file unzip read.csv #' @importFrom data.table fread #' @export +#' @returns data.frame with historical hydrological data for the semi-annual and annual period #' @examples #' \donttest{ #' hydro_yearly = hydro_imgw_annual(year = 2000, value = "H", station = "ANNOPOL") @@ -72,7 +73,7 @@ hydro_imgw_annual_bp = function(year = year, ind = grep(readHTMLTable(a)[[1]]$Name, pattern = "/") catalogs = as.character(readHTMLTable(a)[[1]]$Name[ind]) catalogs = gsub(x = catalogs, pattern = "/", replacement = "") - # less files to read: + catalogs = catalogs[catalogs %in% as.character(year)] if (length(catalogs) == 0) { stop("Selected year(s) is/are not available in the database.", call. = FALSE) @@ -81,10 +82,7 @@ hydro_imgw_annual_bp = function(year = year, all_data = vector("list", length = length(catalogs)) for (i in seq_along(catalogs)) { - # i = 1 catalog = catalogs[i] - #print(i) - address = paste0(base_url, interval_pl, "/", catalog, "/polr_", value, "_", catalog, ".zip") temp = tempfile() @@ -104,19 +102,19 @@ hydro_imgw_annual_bp = function(year = year, all_data[[i]] = data1 } all_data = do.call(rbind, all_data) - # ten sam warunek braku danych lub obserwacji dla wszytkich wartosci all_data[all_data == 99999.999] = NA all_data = all_data[, !duplicated(colnames(all_data))] # coords if (coords) { - all_data = merge(climate::imgw_hydro_stations, all_data, by.x = "id", by.y = "Kod stacji", all.y = TRUE) + all_data = merge(climate::imgw_hydro_stations, all_data, by.x = "id", by.y = "Nazwa rzeki/jeziora", all.y = TRUE) } #station selection if (!is.null(station)) { if (is.character(station)) { all_data = all_data[substr(all_data$`Nazwa stacji`, 1, nchar(station)) == station, ] if (nrow(all_data) == 0) { + stop("Selected station(s) is not available in the database.", call. = FALSE) } } else if (is.numeric(station)) { diff --git a/R/hydro_imgw_daily.R b/R/hydro_imgw_daily.R index a1940ed8..3b0d13d7 100644 --- a/R/hydro_imgw_daily.R +++ b/R/hydro_imgw_daily.R @@ -16,7 +16,7 @@ #' @importFrom utils download.file unzip read.csv #' @importFrom data.table fread #' @export -#' +#' @returns data.frame with historical hydrological data for the daily time interval #' @examples \donttest{ #' daily = hydro_imgw_daily(year = 2000) #' } @@ -76,7 +76,6 @@ hydro_imgw_daily_bp = function(year, all_data = vector("list", length = length(catalogs)) for (i in seq_along(catalogs)) { catalog = catalogs[i] - # print(i) iterator = c("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12") data = NULL @@ -96,17 +95,9 @@ hydro_imgw_daily_bp = function(year, } # extra exception for a current year according to information provided by IMGW-PIB: # i.e.: - # "Do czasu zakończenia kontroli przepływów z roku hydrologicznego 2020 (do około poczatku sierpnia 2021), - # rekordy z danymi z roku 2020 mają format: - #Kod stacji - #Nazwa stacji - #Nazwa rzeki/jeziora - #Rok hydrologiczny - #Wskaźnik miesiąca w roku hydrologicznym - #Dzień - #Stan wody [cm] - #Temperatura wody [st. C] - #Miesiąc kalendarzowy + # "Do czasu zakonczenia kontroli przeplywow rekordy z danymi z roku 2020 maja format: + #Kod stacji #Nazwa stacji #Nazwa rzeki/jeziora #Rok hydrologiczny #Wskaznik miesiaca w roku hydrologicznym + #Dzien #Stan wody [cm] #Temperatura wody [st. C] #Miesiac kalendarzowy if (ncol(data1) == 9) { data1$flow = NA data1 = data1[, c(1:7, 10, 8:9)] @@ -131,9 +122,7 @@ hydro_imgw_daily_bp = function(year, colnames(data2) = meta[[2]][, 1] all_data[[i]] = merge(data, data2, - by = c("Kod stacji", "Nazwa stacji", - "Rok hydrologiczny", "Nazwa rzeki/jeziora", - "Wskaznik miesiaca w roku hydrologicznym", "Dzien"), + by = intersect(colnames(data), colnames(data2)), all.x = TRUE) } @@ -166,11 +155,7 @@ hydro_imgw_daily_bp = function(year, } } - all_data = all_data[order(all_data$`Nazwa stacji`, - all_data$`Rok hydrologiczny`, - all_data$`Wskaznik miesiaca w roku hydrologicznym`, - all_data$`Dzien`), ] - # dodanie opcji dla skracania kolumn i usuwania duplikatow: + all_data = all_data[do.call(order, all_data[grep(x = colnames(all_data), "Nazwa stacji|Rok hydro|w roku hydro|Dzie")]), ] all_data = hydro_shortening_imgw(all_data, col_names = col_names, ...) return(all_data) diff --git a/R/hydro_imgw_monthly.R b/R/hydro_imgw_monthly.R index ce7c605e..cacb8291 100644 --- a/R/hydro_imgw_monthly.R +++ b/R/hydro_imgw_monthly.R @@ -16,6 +16,7 @@ #' @importFrom utils download.file unzip read.csv #' @importFrom data.table fread #' @export +#' @returns data.frame with historical hydrological data for the monthly summaries #' #' @examples \donttest{ #' monthly = hydro_imgw_monthly(year = 2000) @@ -120,10 +121,7 @@ hydro_imgw_monthly_bp = function(year, stop("Selected station(s) are not in the proper format.", call. = FALSE) } } - - all_data = all_data[order(all_data$`Nazwa stacji`, - all_data$`Rok hydrologiczny`, - all_data$`Wskaznik miesiaca w roku hydrologicznym`), ] + all_data = all_data[do.call(order, all_data[grep(x = colnames(all_data), "Nazwa stacji|Rok hydrologiczny|w roku hydro")]), ] all_data = hydro_shortening_imgw(all_data, col_names = col_names, ...) return(all_data) diff --git a/R/hydro_metadata_imgw.R b/R/hydro_metadata_imgw.R index f0b2f02d..20028195 100644 --- a/R/hydro_metadata_imgw.R +++ b/R/hydro_metadata_imgw.R @@ -6,12 +6,7 @@ #' @param interval temporal resolution of the data ("daily" , "monthly", or "semiannual_and_annual") #' @param allow_failure logical - whether to proceed or stop on failure. By default set to TRUE (i.e. don't stop on error). For debugging purposes change to FALSE #' @keywords internal -#' @examples -#' \donttest{ -#' meta = climate:::hydro_metadata_imgw(interval = "daily") -#' meta = climate:::hydro_metadata_imgw(interval = "monthly") -#' meta = climate:::hydro_metadata_imgw(interval = "semiannual_and_annual") -#' } +#' @noRd hydro_metadata_imgw = function(interval, allow_failure = TRUE) { diff --git a/R/hydro_shortening_imgw.R b/R/hydro_shortening_imgw.R index 59cc8e7a..e4bfeac7 100644 --- a/R/hydro_shortening_imgw.R +++ b/R/hydro_shortening_imgw.R @@ -9,13 +9,14 @@ #' "polish" - original names in the dataset #' @param remove_duplicates whether to remove duplicated column names #' (default TRUE - i.e., columns with duplicated names are deleted) -#' @keywords internal +#' @export +#' @returns data.frame with shorten names of hydrological parameters #' @examples #' \donttest{ -#' monthly = hydro_imgw("monthly", year = 1969) +#' monthly = data = hydro_imgw("monthly", year = 1969, col_names = "polish") #' #' if (is.data.frame(monthly)) { -#' abbr = climate:::hydro_shortening_imgw(data = monthly, +#' abbr = hydro_shortening_imgw(data = monthly, #' col_names = "full", #' remove_duplicates = TRUE) #' head(abbr) diff --git a/R/meteo_imgw.R b/R/meteo_imgw.R index ace785f2..4e66261e 100644 --- a/R/meteo_imgw.R +++ b/R/meteo_imgw.R @@ -1,7 +1,7 @@ -#' Meteorological data from IMGW +#' Meteorological data from the IMGW-PIB official repository #' #' Downloading hourly, daily, and monthly meteorological data from the -#' SYNOP / CLIMATE / PRECIP stations available in the danepubliczne.imgw.pl collection +#' SYNOP / CLIMATE / PRECIP stations available in the danepubliczne.imgw.pl collection. #' #' @param interval temporal resolution of the data ("hourly", "daily", "monthly") #' @param rank rank of the stations: "synop" (default), "climate" or "precip" diff --git a/R/meteo_imgw_daily.R b/R/meteo_imgw_daily.R index 1060dac3..b3ee431c 100644 --- a/R/meteo_imgw_daily.R +++ b/R/meteo_imgw_daily.R @@ -20,6 +20,7 @@ #' @importFrom XML readHTMLTable #' @importFrom utils download.file unzip read.csv #' @importFrom data.table fread +#' @returns data.frame with a daily meteorological measurements #' @export #' #' @examples \donttest{ @@ -88,7 +89,7 @@ meteo_imgw_daily_bp = function(rank, split = "_") years_in_catalogs = lapply(years_in_catalogs, function(x) x[1]:x[length(x)]) ind = lapply(years_in_catalogs, function(x) sum(x %in% year) > 0) - catalogs = catalogs[unlist(ind)] # to sa nasze prawdziwe catalogs do przemielenia + catalogs = catalogs[unlist(ind)] all_data = NULL @@ -163,9 +164,6 @@ meteo_imgw_daily_bp = function(rank, ind = grep(readHTMLTable(folder_contents)[[1]]$Name, pattern = "zip") files = as.character(readHTMLTable(folder_contents)[[1]]$Name[ind]) addresses_to_download = paste0(address, files) - # w tym miejscu trzeba przemyslec fragment kodu - # do dodania dla pojedynczej stacji jesli tak sobie zazyczy uzytkownik: - # na podstawie zawartosci obiektu files for (j in seq_along(addresses_to_download)) { temp = tempfile() @@ -199,11 +197,11 @@ meteo_imgw_daily_bp = function(rank, data2, by = c("Kod stacji", "Rok", "Miesiac", "Dzien"), all.x = TRUE) - } # koniec petli po zipach do pobrania - } # koniec if'a dla klimatu + } # end of looping for zip files + } # end of if statement for climate stations - ###################### - ######## OPAD: ####### + ######################## + ######## PRECIP: ####### if (rank == "precip") { address = paste0(base_url, "dane_meteorologiczne/dobowe/opad", "/", catalog, "/") @@ -236,10 +234,9 @@ meteo_imgw_daily_bp = function(rank, unlink(c(temp, temp2)) all_data[[length(all_data) + 1]] = data1 - } # koniec petli po zipach do pobrania - } # koniec if'a dla klimatu - - } # koniec petli po glownych catalogach danych dobowych + } # end of loop for zip files + } # end of if statement for climate stations + } # end of looping over catalogs all_data = do.call(rbind, all_data) @@ -251,11 +248,11 @@ meteo_imgw_daily_bp = function(rank, all.y = TRUE) } - # dodaje rank + # add station rank: rank_code = switch(rank, synop = "SYNOPTYCZNA", climate = "KLIMATYCZNA", precip = "OPADOWA") all_data = cbind(data.frame(rank_code = rank_code), all_data) - all_data = all_data[all_data$Rok %in% year, ] # przyciecie tylko do wybranych lat gdyby sie pobralo za duzo + all_data = all_data[all_data$Rok %in% year, ] # clip only to selected years #station selection if (!is.null(station)) { diff --git a/R/meteo_imgw_datastore.R b/R/meteo_imgw_datastore.R index fbf357dc..b864eaba 100644 --- a/R/meteo_imgw_datastore.R +++ b/R/meteo_imgw_datastore.R @@ -29,9 +29,9 @@ #' @param allow_failure logical - whether to proceed or stop on failure. By default set to TRUE (i.e. don't stop on error). For debugging purposes change to FALSE #' @import data.table #' @export -#' -#' @examples \donttest{ -#' # download only air temperature for selected 2 stations in 2022-2023: +#' @returns data.frame with a raw meteorological measurements in 10-min intervals +#' @examples +#' \donttest{ #' imgw_telemetry = meteo_imgw_datastore(year = 2022:2023, #' parameters = "t2m", #' stations = c("HALA GĄSIENICOWA", diff --git a/R/meteo_imgw_hourly.R b/R/meteo_imgw_hourly.R index 026c5de0..380a5630 100644 --- a/R/meteo_imgw_hourly.R +++ b/R/meteo_imgw_hourly.R @@ -20,6 +20,7 @@ #' @importFrom utils download.file unzip read.csv #' @importFrom data.table fread #' @export +#' @return meteorological data for the hourly time interval #' #' @examples \donttest{ #' hourly = meteo_imgw_hourly(rank = "climate", year = 1984) diff --git a/R/meteo_imgw_monthly.R b/R/meteo_imgw_monthly.R index 4b37858b..85bb651a 100644 --- a/R/meteo_imgw_monthly.R +++ b/R/meteo_imgw_monthly.R @@ -9,19 +9,24 @@ #' (default status = FALSE - i.e. the status columns are deleted) #' @param coords add coordinates of the station (logical value TRUE or FALSE) #' @param station name or ID of meteorological station(s). -#' It accepts names (characters in CAPITAL LETTERS) or stations' IDs (numeric) +#' It accepts names (characters in CAPITAL LETTERS) or stations' IDs (numeric). +#' Please note that station names may change over time and thus sometimes 2 names +#' are required in some cases, e.g. `c("POZNAŃ", "POZNAŃ-ŁAWICA")`. #' @param col_names three types of column names possible: "short" - default, #' values with shorten names, "full" - full English description, #' "polish" - original names in the dataset -#' @param allow_failure logical - whether to proceed or stop on failure. By default set to TRUE (i.e. don't stop on error). For debugging purposes change to FALSE +#' @param allow_failure logical - whether to proceed or stop on failure. +#' By default set to TRUE (i.e. don't stop on error). For debugging purposes change to FALSE #' @param ... other parameters that may be passed to the #' 'shortening' function that shortens column names #' @importFrom XML readHTMLTable #' @importFrom utils unzip read.csv #' @importFrom data.table fread #' @export +#' @return meteorological data with monthly summaries #' -#' @examples \donttest{ +#' @examples +#' \donttest{ #' monthly = meteo_imgw_monthly(rank = "climate", year = 1969) #' head(monthly) #' @@ -29,11 +34,6 @@ #' monthly2 = meteo_imgw_monthly(rank = "synop", year = 2018, #' col_names = "full") #' head(monthly2) -#' -#' # please note that station names may change over time -#' # and thus 2 names are required in some cases: -#' # df = meteo_imgw_monthly(rank = 'synop', year = 1991:2000, -#' # coords = TRUE, station = c("POZNAŃ","POZNAŃ-ŁAWICA")) #' } #' meteo_imgw_monthly = function(rank = "synop", @@ -102,7 +102,6 @@ meteo_imgw_monthly_bp = function(rank, all_data = vector("list", length = length(catalogs)) for (i in seq_along(catalogs)) { - # print(i) catalog = gsub(catalogs[i], pattern = "/", replacement = "") if (rank == "synop") { diff --git a/R/meteo_metadata_imgw.R b/R/meteo_metadata_imgw.R index ad9c6d3a..95e02913 100644 --- a/R/meteo_metadata_imgw.R +++ b/R/meteo_metadata_imgw.R @@ -1,18 +1,13 @@ #' Meteorological metadata #' -#' Downloading the description (metadata) to the meteorological data available in the dane.imgw repository.imgw.pl. +#' Downloading the description (metadata) to the meteorological data available in the +#' danepubliczne.imgw.pl collection. #' By default, the function returns a list or data frame for a selected subset #' #' @param interval temporal resolution of the data ("hourly", "daily", "monthly") #' @param rank rank of station ("synop", "climate", "precip") #' @keywords internal -#' -#' @examples -#' \donttest{ -#' #meta = climate:::meteo_metadata_imgw(interval = "hourly", rank = "synop") -#' #meta = climate:::meteo_metadata_imgw(interval = "daily", rank = "synop") -#' #meta = climate:::meteo_metadata_imgw(interval = "monthly", rank = "precip") -#' } +#' @noRd meteo_metadata_imgw = function(interval, rank) { # interval can be: monthly, hourly, hourly @@ -64,7 +59,7 @@ meteo_metadata_imgw = function(interval, rank) { # interval can be: monthly, hou rank = "precip", interval = "monthly") } - } # koniec MIESIECZNYCH + } # end of monthly interval ## hourly data section: if (interval == "hourly") { diff --git a/R/meteo_noaa_co2.R b/R/meteo_noaa_co2.R index 33f9ed95..99de085c 100644 --- a/R/meteo_noaa_co2.R +++ b/R/meteo_noaa_co2.R @@ -34,11 +34,12 @@ #' @importFrom utils read.table #' @importFrom utils data #' @export +#' @returns Data frame with historical CO2 concentrations #' -#' @examples \donttest{ -#' #co2 = meteo_noaa_co2() -#' #head(co2) -#' #plot(co2$yy_d, co2$co2_avg, type='l') +#' @examples +#' \donttest{ +#' co2 = meteo_noaa_co2() +#' head(co2) #' } #' @@ -56,7 +57,7 @@ meteo_noaa_co2 = function() { colnames(co2) = c("yy", "mm", "yy_d","co2_avg", "co2_interp", "co2_seas", "ndays", "st_dev_days") } else { - cat(paste0("Service not working or problems with internet connection. Check url:\n", base_url)) + message(paste0("Service not working or problems with internet connection. Check url:\n", base_url)) } unlink(temp) diff --git a/R/meteo_noaa_hourly.R b/R/meteo_noaa_hourly.R index a550fd58..2604be1a 100644 --- a/R/meteo_noaa_hourly.R +++ b/R/meteo_noaa_hourly.R @@ -11,14 +11,13 @@ #' @param allow_failure logical - whether to proceed or stop on failure. By default set to TRUE (i.e. don't stop on error). For debugging purposes change to FALSE #' @importFrom utils download.file unzip read.csv #' @export +#' @returns data.frame with historical meteorological data in hourly intervals #' #' @examples #' \donttest{ #' # London-Heathrow, United Kingdom #' noaa = meteo_noaa_hourly(station = "037720-99999", year = 1949) #' } -#' - meteo_noaa_hourly = function(station = NULL, year = 2019, @@ -91,7 +90,7 @@ meteo_noaa_hourly_bp = function(station = station, year, fm12 = fm12) { dat$slp = dat$slp/10 } else { - cat(paste0(" Check station name or year. The URL is not working properly:\n ", address)) + message(paste0(" Check station name or year. The URL is not working properly:\n ", address)) } # end of if statement for empty files all_data[[length(all_data) + 1]] = dat diff --git a/R/meteo_shortening_imgw.R b/R/meteo_shortening_imgw.R index 2b380c4a..4f0fdbfd 100644 --- a/R/meteo_shortening_imgw.R +++ b/R/meteo_shortening_imgw.R @@ -5,13 +5,14 @@ #' @param data downloaded dataset with original column names #' @param col_names three types of column names possible: "short" - default, values with shorten names, "full" - full English description, "polish" - original names in the dataset #' @param remove_duplicates whether to remove duplicated column names (default TRUE - i.e., columns with duplicated names are deleted) -#' @keywords internal +#' @export +#' @returns data.frame with modified names of meteorological parameters #' #' @examples #' \donttest{ #' monthly = meteo_imgw("monthly", rank = "climate", year = 1969) -#' colnames(monthly) -#' abbr = climate:::meteo_shortening_imgw(data = monthly, +#' +#' abbr = meteo_shortening_imgw(data = monthly, #' col_names = "full", #' remove_duplicates = TRUE) #' head(abbr) diff --git a/R/nearest_stations_ogimet.R b/R/nearest_stations_ogimet.R index 0b0b63fd..ab4973ab 100644 --- a/R/nearest_stations_ogimet.R +++ b/R/nearest_stations_ogimet.R @@ -19,10 +19,10 @@ #' #' @examples #' \donttest{ -#' nearest_stations_ogimet(country = "Uniced Kingdom", +#' nearest_stations_ogimet(country = "United Kingdom", #' point = c(-2, 50), #' add_map = TRUE, -#' no_of_stations = 0, +#' no_of_stations = 50, #' allow_failure = TRUE, #' main = "Meteo stations in UK") #' } @@ -157,7 +157,7 @@ nearest_stations_ogimet_bp = function(country = country, result = rbind(result,res) } else { result = NULL - cat(paste("Wrong name of a country. Please check countries names at + message(paste("Wrong name of a country. Please check countries names at https://ogimet.com/display_stations.php?lang=en&tipo=AND&isyn=&oaci=&nombre=&estado=&Send=Send")) } # end of checking internet connection diff --git a/R/ogimet_daily.R b/R/ogimet_daily.R index 063b9219..aaaf6f19 100644 --- a/R/ogimet_daily.R +++ b/R/ogimet_daily.R @@ -12,10 +12,10 @@ #' @importFrom utils setTxtProgressBar txtProgressBar #' #' @export -#' -#' @keywords internal +#' @returns data.frame with historical meteorological data for the daily summaries #' -#' @examples \donttest{ +#' @examples +#' \donttest{ #' # downloading daily summaries for last 30 days. station: New York - La Guardia #' new_york = ogimet_daily(station = 72503, coords = TRUE) #' } @@ -78,7 +78,7 @@ ogimet_daily_bp = function(date = date, ) for (station_nr in station) { - print(station_nr) + message(station_nr) # adding progress bar if at least 3 iterations are needed if (length(dates) * length(station) >= 3) { diff --git a/R/ogimet_hourly.R b/R/ogimet_hourly.R index 6b7ba196..b69c63e0 100644 --- a/R/ogimet_hourly.R +++ b/R/ogimet_hourly.R @@ -12,6 +12,7 @@ #' @export #' #' @keywords internal +#' @returns data.frame with historical meteorological data for hourly time interval #' #' @examples #' \donttest{ @@ -80,14 +81,13 @@ ogimet_hourly_bp = function(date = date, ) for (station_nr in station) { - print(station_nr) + message(station_nr) # adding progress bar if at least 3 iterations are needed if (length(dates)*length(station) >= 3 ) pb = txtProgressBar(min = 0, max = length(dates)*length(station) - 1, style = 3) -# print(station_nr) for (i in length(dates):1) { - if (length(dates) >= 3 ) paste(setTxtProgressBar(pb, abs(length(dates)*length(station) - i)), "\n") + if (length(dates) >= 3 ) paste(setTxtProgressBar(pb, abs(length(dates) * length(station) - i)), "\n") year = format(dates[i], "%Y") month = format(dates[i], "%m") @@ -183,7 +183,6 @@ ogimet_hourly_bp = function(date = date, suppressWarnings(data_station[, columns] <- as.data.frame(sapply(data_station[,columns], as.numeric))) - # TODO: # changing order of columns and removing blank records: if (coords) { ord1 = c("station_ID", "Lon", "Lat", "Date", "TC") diff --git a/R/onAttach.R b/R/onAttach.R index b4a22711..dd2d0349 100644 --- a/R/onAttach.R +++ b/R/onAttach.R @@ -4,7 +4,7 @@ #' @export .onAttach = function(libname, pkgname) { - if ((runif (1) < 0.25) & interactive()) { # activate occasionally and only if not run as Rscript + if ((runif(1) < 0.25) & interactive()) { # activate occasionally and only if not run as Rscript ver = as.character(packageVersion("climate")) packageStartupMessage(paste0(c("\n____________________________________________________________________\n", " Welcome to climate ", ver, "!", diff --git a/R/precip_split.R b/R/precip_split.R index 90fec86e..e133317f 100644 --- a/R/precip_split.R +++ b/R/precip_split.R @@ -5,15 +5,8 @@ #' @param pattern 6h-12h-24h precipitation pattern to obtain written as: "/6h", "/12h" , "/24h" (see examples) #' #' @keywords internal -#' -#' @examples -#' \donttest{ -#' df = tryCatch(ogimet_hourly(station = 12330), error = function(e) 0) -#' if (is.data.frame(df)) { -#' climate:::precip_split(df$Precmm, pattern = "/12") # to get 12h precipitation amounts -#' } -#' } -#' +#' @noRd + precip_split = function(precip, pattern = "/12") { b = strsplit(precip, "h", fixed = TRUE) b = lapply(b, function(x) x[grepl(x, pattern = pattern, fixed = TRUE)]) diff --git a/R/profile_demo.R b/R/profile_demo.R index 0d957cea..df0641bf 100644 --- a/R/profile_demo.R +++ b/R/profile_demo.R @@ -1,7 +1,7 @@ #' @name profile_demo #' @title Exemplary sounding profile from University of Wyoming dataset #' -#' @description The object contains pre-downloaded atmospheric (sounding) profile for Łeba, PL rawinsonde station. +#' @description The object contains pre-downloaded atmospheric (sounding) profile for Leba, PL rawinsonde station. #' The measurement was taken 2000/03/23 at 00 UTC. #' #' @importFrom utils data diff --git a/R/sounding_wyoming.R b/R/sounding_wyoming.R index 03eb18de..adba96bd 100644 --- a/R/sounding_wyoming.R +++ b/R/sounding_wyoming.R @@ -2,7 +2,7 @@ #' #' Downloading the measurements of the vertical profile of atmosphere (also known as sounding data). Data can be retrieved using TEMP and BUFR sounding formatting. #' -#' @param wmo_id international WMO station code (World Meteorological Organization ID); For Polish stations: Łeba - 12120, Legionowo - 12374, Wrocław- 12425 +#' @param wmo_id international WMO station code (World Meteorological Organization ID); For Polish stations: Leba - 12120, Legionowo - 12374, Wrocław- 12425 #' @param yy year - single number #' @param mm month - single number denoting month #' @param dd day - single number denoting day @@ -41,11 +41,11 @@ #' ############################################################################## #' TEMP = sounding_wyoming(wmo_id = 45004, yy = 2021, mm = 07, dd = 17, #' hh = 12, min = 00) -#' #head(TEMP[[1]]) +#' head(TEMP[[1]]) #' #' BUFR = sounding_wyoming(wmo_id = 45004, yy = 2021, mm = 07, dd = 17, #' hh = 12, min = 00, bufr = TRUE) -#' #head(BUFR[[1]]) +#' head(BUFR[[1]]) #' #' #' ############################################################################## @@ -57,7 +57,6 @@ #' mm = sample(1:12,1), #' dd = sample(1:20,1), #' hh = 0) -#' # head(profile) #' # plot(profile[[1]]$HGHT, profile[[1]]$PRES, type = 'l') #' } #' @@ -150,7 +149,7 @@ sounding_wyoming_bp = function(wmo_id, df = list(df, df2) } else { # end of checking file size / problems with internet connection - cat(paste0("Service not working or wmo_id or date not correct. Check url:\n", url)) + message(paste0("Service not working or wmo_id or date not correct. Check url:\n", url)) } unlink(temp) diff --git a/R/spheroid_dist.R b/R/spheroid_dist.R index 4adf33c6..b577cdb0 100644 --- a/R/spheroid_dist.R +++ b/R/spheroid_dist.R @@ -7,12 +7,11 @@ #' @param p1 coordinates of the first point in decimal degrees (LON, LAT) #' @param p2 coordinates of the second point in decimal degrees (LON, LAT) #' -#' @return distance between two locations in kilometers +#' @return numerical vector with distance between two locations (in kilometers) #' @export - #' @examples -#' p1 = c(18.633333, 54.366667) # longitude and latitude for Gdansk -#' p2 = c(17.016667, 54.466667) # longitude and latitude for Slupsk +#' p1 = c(18.633333, 54.366667) # longitude and latitude for Gdansk, PL +#' p2 = c(17.016667, 54.466667) # longitude and latitude for Slupsk, PL #' spheroid_dist(p1, p2) #' spheroid_dist = function(p1, p2) { diff --git a/R/stations_meteo_imgw_telemetry.R b/R/stations_meteo_imgw_telemetry.R index 550fcb44..e2660bfc 100644 --- a/R/stations_meteo_imgw_telemetry.R +++ b/R/stations_meteo_imgw_telemetry.R @@ -2,11 +2,13 @@ #' #' Retrieving current metadata for stations used in the telemetric systems of the IMGW-PIB datastore (danepubliczne.imgw.pl/datastore) #' -#' @return data table with metadata for over 500 stations. Metadata contains: station ID, station name, river, latitude, longitude, altitude +#' @return data table with metadata for over 500 stations. +#' Metadata contains: station ID, station name, river, latitude, longitude, altitude #' @importFrom data.table as.data.table #' @export #' -#' @examples \donttest{ +#' @examples +#' \donttest{ #' telemetry_stations = stations_meteo_imgw_telemetry() #' } #' diff --git a/R/stations_ogimet.R b/R/stations_ogimet.R index bf617ec7..817737cf 100644 --- a/R/stations_ogimet.R +++ b/R/stations_ogimet.R @@ -2,9 +2,9 @@ #' #' Returns a list of meteorological stations with their coordinates from the Ogimet webpage. The returned list is valid only for a given day #' -#' @param country country name; for more than two words they need to be separated with a plus character (e.g. "United+Kingdom") +#' @param country country name; Every word must be written with capital letters (e.g. "United Kingdom") #' @param date a day when measurements were done in all available locations -#' @param add_map logical - whether to draw a map with downloaded metadata (requires maps/mapdata packages) +#' @param add_map logical - whether to draw a map based on downloaded dataset (requires `maps` package) #' @param allow_failure logical - whether to proceed or stop on failure. By default set to TRUE (i.e. don't stop on error). For debugging purposes change to FALSE #' @importFrom XML readHTMLTable #' @export @@ -16,9 +16,8 @@ #' stations_ogimet(country = "Australia", add_map = TRUE) #' } #' -#' -stations_ogimet = function(country = "United+Kingdom", +stations_ogimet = function(country = "United Kingdom", date = Sys.Date(), add_map = FALSE, allow_failure = TRUE) { @@ -41,6 +40,8 @@ stations_ogimet_bp = function(country = country, date = date, add_map = add_map) stop("Too many countries selected. Please choose only one country") } + country = gsub(x = country, pattern = " ", replacement = "+") + if (length(date) != 1) { stop("You can check available nearest stations for one day. Please chenge selection") @@ -113,7 +114,7 @@ stations_ogimet_bp = function(country = country, date = date, add_map = add_map) } else { res = NULL - cat(paste("Wrong name of a country or problems with internet connection.", + message(paste("Wrong name of a country or problems with internet connection.", "Please check countries names at:\n", "https://ogimet.com/display_stations.php?lang=en&tipo=AND&isyn=&oaci=&nombre=&estado=&Send=Send")) } # end of checking problems with internet connection: diff --git a/R/test_url.R b/R/test_url.R index 06169b34..76510359 100644 --- a/R/test_url.R +++ b/R/test_url.R @@ -1,17 +1,19 @@ #' Download file in a graceful way #' #' Function for downloading & testing url/internet connection according to CRAN policy -#' Example solution strongly based on https://community.rstudio.com/t/internet-resources-should-fail-gracefully/49199/12 +#' Example solution strongly based on +#' https://community.rstudio.com/t/internet-resources-should-fail-gracefully/49199/12 #' as suggested by kvasilopoulos #' #' @param link character vector with URL to check #' @param output character vector for output file name -#' @param quiet logical vector (TRUE or FALSE) to be passed to curl_download function. FALSE by default +#' @param quiet logical vector (TRUE or FALSE) to be passed to curl_download function. +#' FALSE by default #' #' @importFrom curl curl_download #' @importFrom curl has_internet #' @import httr -#' +#' @return No return value, called for side effects #' @export #' #' @examples @@ -22,10 +24,7 @@ #' } #' - - test_url = function(link, output, quiet = FALSE) { - print(link) try_GET = function(x, ...) { tryCatch( curl::curl_download(url = link, destfile = output, mode = "wb", quiet = quiet, ...), @@ -54,17 +53,4 @@ test_url = function(link, output, quiet = FALSE) { message(paste0("\nCheck: ", link, " in your browser!\n")) return(invisible(NULL)) } - } - -# b = gracefully_fail("http://httpbin.org/status/404") # http >400 -# #> Not Found (HTTP 404). -# gracefully_fail("http://httpbin.org/delay/11") # Timeout -# #> Timeout was reached: [httpbin.org] Operation timed out after 1000 milliseconds with 0 bytes received -# a = gracefully_fail("http://httpbin.org") #OK -# -# b = curl_download(url = "http://httpbin.org", destfile = tempfile()) -# b = curl_download(url = "http://httpbin.org/status/404", destfile = tempfile()) -# -# url = "http://www2.census.gov/acs2011_5yr/pums/csv_pus.zip" -# test_url(link = url, output = tempfile()) diff --git a/data-raw/hydro_parametry_skroty.csv b/data-raw/hydro_parametry_skroty.csv index ed29e7a9..22b425cd 100644 --- a/data-raw/hydro_parametry_skroty.csv +++ b/data-raw/hydro_parametry_skroty.csv @@ -1,23 +1,28 @@ fullname;abbr_eng;fullname_eng;; Kod stacji;id;ID;; Dzien;dd;Day;; -Miesiac kalendarzowy;mm;Month;; +Dzień;dd;Day;; +Miesiąc kalendarzowy;mm;Month;; Nazwa rzeki/jeziora;riv_or_lake;River_or_Lake;; Nazwa stacji;station;Station;; -Przeplyw [m^3/s];Q;Flow [m3_s];; -Rodzaj wielkosci (H - stan wody, Q - przeplyw, T - temperatura wody);Mesu;"Measurement [state - H, flow - Q, or temperature - T]""";;` +Przepływ [m^3/s];Q;Flow [m3_s];; +Rodzaj wielkości (H - stan wody, Q - przepływ, T - temperatura wody);Mesu;Measurement [state - H, flow - Q, or temperature - T];;` Rok hydrologiczny;hyy;Hydrologic year;; Stan wody [cm];H;State [cm];; Temperatura wody [st. C];T;Temperature [C];; -Wskaznik ekstremum;idex;Extreme ID [min - 1, mean - 2, Max - 3];; -Wskaznik ekstremum (1 - minimum, 2 - srednia, 3 - maksimum);idex;Extreme ID [min - 1, mean - 2, Max - 3];; -Wskaznik miesiaca w roku hydrologicznym;idhyy;Hydrologic year ID;; -Wskaznik polrocza (13 - zima, 14 - lato, 15 - rok);idyy;Year ID [13 -winter, 14 - summer, 15 - year];; -wystapienie_od_Dzien;bedd;Occurrence from day;; -wystapienie_od_Godzina:Minuta;behm;Occurrence from time;; -wystapienie_od_Miesiac;bemm;Occurrence from month;; -wystapienie_od_Rok;beyy;Occurrence from year;; -Grubosc lodu [cm];thick;Thickness of ice [cm];; -Kod zjawiska lodowego (slownik ponizej);id_ice;Ice phenomena;; -"Procent udzialu zjawiska lodowego [mnoznik *10; np. 3 oznacza 30% udzialu zjawisk lodowych]";p_ice;Percentage of ice phenomena;; -Kod zarastania (slownik ponizej);id_over_grow;Overgrowing;; +Wskaźnik ekstremum;idex;Extreme ID [min - 1, mean - 2, Max - 3];; +Wskaźnik ekstremum (1 - minimum, 2 - średnia, 3 - maksimum);idex;Extreme ID [min - 1, mean - 2, Max - 3];; +Wskaźnik miesiąca w roku hydrologicznym;idhyy;Hydrologic year ID;; +Wskaźnik półrocza (13 - zima, 14 - lato, 15 - rok);idyy;Year ID [13 -winter, 14 - summer, 15 - year];; +wystapienie_od_Dzień;bedd;Occurrence from day;; +wystapienie_od_Godzina:Minuta;behm;Occurrence start time;; +wystapienie_od_Miesiąc;bemm;Occurrence start month;; +wystapienie_od_Rok;beyy;Occurrence start year;; +wystapienie_do_Dzień;bedd;Occurrence start day;; +wystapienie_do_Godzina:Minuta;behm;Occurrence end time;; +wystapienie_do_Miesiąc;bemm;Occurrence end month;; +wystapienie_do_Rok;beyy;Occurrence end year;; +Grubość lodu [cm];thick;Thickness of ice [cm];; +Kod zjawiska lodowego (słownik poniżej);id_ice;Ice phenomena;; +"Procent udziału zjawiska lodowego [mnożnik *10; np. 3 oznacza 30% udziału zjawisk lodowych]";p_ice;Percentage of ice phenomena;; +Kod zarastania (słownik poniżej);id_over_grow;Overgrowing;; diff --git a/data/imgw_hydro_abbrev.rda b/data/imgw_hydro_abbrev.rda index 19968b1c..88c89425 100644 Binary files a/data/imgw_hydro_abbrev.rda and b/data/imgw_hydro_abbrev.rda differ diff --git a/man/clean_metadata_hydro.Rd b/man/clean_metadata_hydro.Rd deleted file mode 100644 index c0263114..00000000 --- a/man/clean_metadata_hydro.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/clean_metadata_hydro.R -\name{clean_metadata_hydro} -\alias{clean_metadata_hydro} -\title{Hydrological metadata cleaning (IMGW-PIB data only)} -\usage{ -clean_metadata_hydro(address, interval) -} -\arguments{ -\item{address}{URL address of the metadata file} - -\item{interval}{temporal interval} -} -\description{ -Internal function for hydrological metadata cleaning -} -\keyword{internal} diff --git a/man/clean_metadata_meteo.Rd b/man/clean_metadata_meteo.Rd deleted file mode 100644 index e759e8d5..00000000 --- a/man/clean_metadata_meteo.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/clean_metadata_meteo.R -\name{clean_metadata_meteo} -\alias{clean_metadata_meteo} -\title{Meteorological metadata cleaning} -\usage{ -clean_metadata_meteo(address, rank = "synop", interval = "hourly") -} -\arguments{ -\item{address}{URL address of the metadata file} - -\item{rank}{stations' rank} - -\item{interval}{temporal interval} -} -\description{ -Internal function for meteorological metadata cleaning -} -\keyword{internal} diff --git a/man/co2_demo.Rd b/man/co2_demo.Rd index 401a82b2..da6b9773 100644 --- a/man/co2_demo.Rd +++ b/man/co2_demo.Rd @@ -10,13 +10,14 @@ An object of class \code{data.frame} with 745 rows and 7 columns. \usage{ co2_demo } +\value{ +data.frame with historical CO2 concentrations +data(co2_demo) +head(co2_demo) +} \description{ The object contains pre-downloaded CO2 dataset from Mauna Loa observatory The snapshot was taken 2020/05/05. } -\examples{ -data(co2_demo) -head(co2_demo) -} \keyword{datasets} \keyword{meteo} diff --git a/man/get_coord_from_string.Rd b/man/get_coord_from_string.Rd deleted file mode 100644 index 1645e424..00000000 --- a/man/get_coord_from_string.Rd +++ /dev/null @@ -1,28 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_coord_from_string.R -\name{get_coord_from_string} -\alias{get_coord_from_string} -\title{Getting coordinates from a string provided by the Ogimet web portal} -\format{ -The returned object is the geographic coordinates using WGS84 (EPSG:4326) in decimal format. -Negative values mean western or southern Hemisphere -} -\usage{ -get_coord_from_string(txt, pattern = "Longitude") -} -\arguments{ -\item{txt}{string with coordinates from Ogimet} - -\item{pattern}{which element (Longitude or Latitude) to extract} -} -\description{ -Internal function for cleaning coordinates' metadata provided by Ogimet -} -\examples{ -\donttest{ - txt = "12120: Leba (Poland)\nLatitude: 54-45N Longitude: 017-32E Altitude: 2 m." - climate:::get_coord_from_string(txt, pattern = "Latitude") -} - -} -\keyword{internal} diff --git a/man/hydro_imgw.Rd b/man/hydro_imgw.Rd index d7516d71..756fab2c 100644 --- a/man/hydro_imgw.Rd +++ b/man/hydro_imgw.Rd @@ -40,7 +40,7 @@ function that shortens column names} A data.frame with columns describing the hydrological parameters (e.g. flow, water level) where each row represent a measurement, depending on the interval, at a given hour, month or year. -If \code{coords = TRUE} additional two columns with geografic coordinates are added. +If \code{coords = TRUE} additional two columns with geographic coordinates are added. } \description{ Downloading daily, and monthly hydrological data from the measurement stations diff --git a/man/hydro_imgw_annual.Rd b/man/hydro_imgw_annual.Rd index 07af47cc..6569b09e 100644 --- a/man/hydro_imgw_annual.Rd +++ b/man/hydro_imgw_annual.Rd @@ -33,6 +33,9 @@ It accepts names (characters in CAPITAL LETTERS) or stations' IDs (numeric)} \item{...}{other parameters that may be passed to the 'shortening' function that shortens column names} } +\value{ +data.frame with historical hydrological data for the semi-annual and annual period +} \description{ Downloading hydrological data for the semi-annual and annual period available in the danepubliczne.imgw.pl collection diff --git a/man/hydro_imgw_daily.Rd b/man/hydro_imgw_daily.Rd index 6c776067..0de9f59b 100644 --- a/man/hydro_imgw_daily.Rd +++ b/man/hydro_imgw_daily.Rd @@ -30,6 +30,9 @@ It accepts names (characters in CAPITAL LETTERS) or stations' IDs (numeric)} \item{...}{other parameters that may be passed to the 'shortening' function that shortens column names} } +\value{ +data.frame with historical hydrological data for the daily time interval +} \description{ Downloading daily hydrological data from the danepubliczne.imgw.pl collection } diff --git a/man/hydro_imgw_monthly.Rd b/man/hydro_imgw_monthly.Rd index 34369e2c..7ec946b3 100644 --- a/man/hydro_imgw_monthly.Rd +++ b/man/hydro_imgw_monthly.Rd @@ -30,6 +30,9 @@ It accepts names (characters in CAPITAL LETTERS) or stations' IDs (numeric)} \item{...}{other parameters that may be passed to the 'shortening' function that shortens column names} } +\value{ +data.frame with historical hydrological data for the monthly summaries +} \description{ Downloading monthly hydrological data from the danepubliczne.imgw.pl collection } diff --git a/man/hydro_metadata_imgw.Rd b/man/hydro_metadata_imgw.Rd deleted file mode 100644 index 5c75c91c..00000000 --- a/man/hydro_metadata_imgw.Rd +++ /dev/null @@ -1,25 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/hydro_metadata_imgw.R -\name{hydro_metadata_imgw} -\alias{hydro_metadata_imgw} -\title{Hydrological metadata} -\usage{ -hydro_metadata_imgw(interval, allow_failure = TRUE) -} -\arguments{ -\item{interval}{temporal resolution of the data ("daily" , "monthly", or "semiannual_and_annual")} - -\item{allow_failure}{logical - whether to proceed or stop on failure. By default set to TRUE (i.e. don't stop on error). For debugging purposes change to FALSE} -} -\description{ -Downloading the description (metadata) to hydrological data available in the danepubliczne.imgw.pl repository. -By default, the function returns a list or data frame for a selected subset -} -\examples{ -\donttest{ - meta = climate:::hydro_metadata_imgw(interval = "daily") - meta = climate:::hydro_metadata_imgw(interval = "monthly") - meta = climate:::hydro_metadata_imgw(interval = "semiannual_and_annual") -} -} -\keyword{internal} diff --git a/man/hydro_shortening_imgw.Rd b/man/hydro_shortening_imgw.Rd index 500bd32f..a477bbcf 100644 --- a/man/hydro_shortening_imgw.Rd +++ b/man/hydro_shortening_imgw.Rd @@ -17,16 +17,19 @@ values with shorten names, \item{remove_duplicates}{whether to remove duplicated column names (default TRUE - i.e., columns with duplicated names are deleted)} } +\value{ +data.frame with shorten names of hydrological parameters +} \description{ Shortening column names of hydrological parameters to improve the readability of downloaded dataset from the danepubliczne.imgw.pl collection and removing duplicated column names } \examples{ \donttest{ - monthly = hydro_imgw("monthly", year = 1969) + monthly = data = hydro_imgw("monthly", year = 1969, col_names = "polish") if (is.data.frame(monthly)) { - abbr = climate:::hydro_shortening_imgw(data = monthly, + abbr = hydro_shortening_imgw(data = monthly, col_names = "full", remove_duplicates = TRUE) head(abbr) @@ -34,4 +37,3 @@ the danepubliczne.imgw.pl collection and removing duplicated column names } } -\keyword{internal} diff --git a/man/meteo_imgw.Rd b/man/meteo_imgw.Rd index fc4a69dd..4ed5913f 100644 --- a/man/meteo_imgw.Rd +++ b/man/meteo_imgw.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/meteo_imgw.R \name{meteo_imgw} \alias{meteo_imgw} -\title{Meteorological data from IMGW} +\title{Meteorological data from the IMGW-PIB official repository} \usage{ meteo_imgw( interval, @@ -45,7 +45,7 @@ columns with geographic coordinates are added. } \description{ Downloading hourly, daily, and monthly meteorological data from the -SYNOP / CLIMATE / PRECIP stations available in the danepubliczne.imgw.pl collection +SYNOP / CLIMATE / PRECIP stations available in the danepubliczne.imgw.pl collection. } \examples{ \donttest{ diff --git a/man/meteo_imgw_daily.Rd b/man/meteo_imgw_daily.Rd index 718bb1db..21f11a5e 100644 --- a/man/meteo_imgw_daily.Rd +++ b/man/meteo_imgw_daily.Rd @@ -38,6 +38,9 @@ It accepts names (characters in CAPITAL LETTERS); Stations' IDs (numeric) are no \item{...}{other parameters that may be passed to the 'shortening' function that shortens column names} } +\value{ +data.frame with a daily meteorological measurements +} \description{ Downloading daily (meteorological) data from the SYNOP / CLIMATE / PRECIP stations available in the danepubliczne.imgw.pl collection diff --git a/man/meteo_imgw_datastore.Rd b/man/meteo_imgw_datastore.Rd index c010be33..1bc73f87 100644 --- a/man/meteo_imgw_datastore.Rd +++ b/man/meteo_imgw_datastore.Rd @@ -43,6 +43,9 @@ Default \code{NULL} means to download data for all available stations. \item{allow_failure}{logical - whether to proceed or stop on failure. By default set to TRUE (i.e. don't stop on error). For debugging purposes change to FALSE} } +\value{ +data.frame with a raw meteorological measurements in 10-min intervals +} \description{ Downloading hourly (meteorological) data from the telemetric stations available in the danepubliczne.imgw.pl/datastore collection since 2008. @@ -54,7 +57,6 @@ Data from the IMGW automated (telemetry) systems are non validated by experts an } \examples{ \donttest{ -# download only air temperature for selected 2 stations in 2022-2023: imgw_telemetry = meteo_imgw_datastore(year = 2022:2023, parameters = "t2m", stations = c("HALA GĄSIENICOWA", diff --git a/man/meteo_imgw_hourly.Rd b/man/meteo_imgw_hourly.Rd index d06f5284..286de97e 100644 --- a/man/meteo_imgw_hourly.Rd +++ b/man/meteo_imgw_hourly.Rd @@ -37,6 +37,9 @@ values with shorten names, "full" - full English description, \item{...}{other parameters that may be passed to the 'shortening' function that shortens column names} } +\value{ +meteorological data for the hourly time interval +} \description{ Downloading hourly (meteorological) data from the SYNOP / CLIMATE / PRECIP stations available in the danepubliczne.imgw.pl collection diff --git a/man/meteo_imgw_monthly.Rd b/man/meteo_imgw_monthly.Rd index 6e3fa206..53583f76 100644 --- a/man/meteo_imgw_monthly.Rd +++ b/man/meteo_imgw_monthly.Rd @@ -26,17 +26,23 @@ meteo_imgw_monthly( \item{coords}{add coordinates of the station (logical value TRUE or FALSE)} \item{station}{name or ID of meteorological station(s). -It accepts names (characters in CAPITAL LETTERS) or stations' IDs (numeric)} +It accepts names (characters in CAPITAL LETTERS) or stations' IDs (numeric). +Please note that station names may change over time and thus sometimes 2 names +are required in some cases, e.g. \code{c("POZNAŃ", "POZNAŃ-ŁAWICA")}.} \item{col_names}{three types of column names possible: "short" - default, values with shorten names, "full" - full English description, "polish" - original names in the dataset} -\item{allow_failure}{logical - whether to proceed or stop on failure. By default set to TRUE (i.e. don't stop on error). For debugging purposes change to FALSE} +\item{allow_failure}{logical - whether to proceed or stop on failure. +By default set to TRUE (i.e. don't stop on error). For debugging purposes change to FALSE} \item{...}{other parameters that may be passed to the 'shortening' function that shortens column names} } +\value{ +meteorological data with monthly summaries +} \description{ Downloading monthly (meteorological) data from the SYNOP / CLIMATE / PRECIP stations available in the danepubliczne.imgw.pl collection @@ -50,11 +56,6 @@ SYNOP / CLIMATE / PRECIP stations available in the danepubliczne.imgw.pl collect monthly2 = meteo_imgw_monthly(rank = "synop", year = 2018, col_names = "full") head(monthly2) - - # please note that station names may change over time - # and thus 2 names are required in some cases: - # df = meteo_imgw_monthly(rank = 'synop', year = 1991:2000, - # coords = TRUE, station = c("POZNAŃ","POZNAŃ-ŁAWICA")) } } diff --git a/man/meteo_metadata_imgw.Rd b/man/meteo_metadata_imgw.Rd deleted file mode 100644 index 6fc0de97..00000000 --- a/man/meteo_metadata_imgw.Rd +++ /dev/null @@ -1,25 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/meteo_metadata_imgw.R -\name{meteo_metadata_imgw} -\alias{meteo_metadata_imgw} -\title{Meteorological metadata} -\usage{ -meteo_metadata_imgw(interval, rank) -} -\arguments{ -\item{interval}{temporal resolution of the data ("hourly", "daily", "monthly")} - -\item{rank}{rank of station ("synop", "climate", "precip")} -} -\description{ -Downloading the description (metadata) to the meteorological data available in the dane.imgw repository.imgw.pl. -By default, the function returns a list or data frame for a selected subset -} -\examples{ -\donttest{ - #meta = climate:::meteo_metadata_imgw(interval = "hourly", rank = "synop") - #meta = climate:::meteo_metadata_imgw(interval = "daily", rank = "synop") - #meta = climate:::meteo_metadata_imgw(interval = "monthly", rank = "precip") -} -} -\keyword{internal} diff --git a/man/meteo_noaa_co2.Rd b/man/meteo_noaa_co2.Rd index 5f21101a..54891214 100644 --- a/man/meteo_noaa_co2.Rd +++ b/man/meteo_noaa_co2.Rd @@ -6,6 +6,9 @@ \usage{ meteo_noaa_co2() } +\value{ +Data frame with historical CO2 concentrations +} \description{ Carbon Dioxide (CO2) monthly measurements from Mauna Loa observatory. The source file is available at: ftp://aftp.cmdl.noaa.gov/products/trends/co2/co2_mm_mlo.txt with all further details. @@ -38,9 +41,8 @@ CO2 expressed as a mole fraction in dry air, micromol/mol, abbreviated as ppm } \examples{ \donttest{ - #co2 = meteo_noaa_co2() - #head(co2) - #plot(co2$yy_d, co2$co2_avg, type='l') + co2 = meteo_noaa_co2() + head(co2) } } diff --git a/man/meteo_noaa_hourly.Rd b/man/meteo_noaa_hourly.Rd index a77a2e53..b9a5b2bd 100644 --- a/man/meteo_noaa_hourly.Rd +++ b/man/meteo_noaa_hourly.Rd @@ -20,6 +20,9 @@ meteo_noaa_hourly( \item{allow_failure}{logical - whether to proceed or stop on failure. By default set to TRUE (i.e. don't stop on error). For debugging purposes change to FALSE} } +\value{ +data.frame with historical meteorological data in hourly intervals +} \description{ Downloading hourly (meteorological) data from the SYNOP stations available in the NOAA ISD collection. Some stations in the dataset are dated back even up to 1900. @@ -31,5 +34,4 @@ Further details available at: https://www1.ncdc.noaa.gov/pub/data/noaa/readme.tx # London-Heathrow, United Kingdom noaa = meteo_noaa_hourly(station = "037720-99999", year = 1949) } - } diff --git a/man/meteo_shortening_imgw.Rd b/man/meteo_shortening_imgw.Rd index 48dfd175..df754523 100644 --- a/man/meteo_shortening_imgw.Rd +++ b/man/meteo_shortening_imgw.Rd @@ -13,18 +13,20 @@ meteo_shortening_imgw(data, col_names = "short", remove_duplicates = TRUE) \item{remove_duplicates}{whether to remove duplicated column names (default TRUE - i.e., columns with duplicated names are deleted)} } +\value{ +data.frame with modified names of meteorological parameters +} \description{ Shortening column names of meteorological parameters to improve the readability of downloaded dataset from the danepubliczne.imgw.pl collection and removing duplicated column names } \examples{ \donttest{ monthly = meteo_imgw("monthly", rank = "climate", year = 1969) - colnames(monthly) - abbr = climate:::meteo_shortening_imgw(data = monthly, + + abbr = meteo_shortening_imgw(data = monthly, col_names = "full", remove_duplicates = TRUE) head(abbr) } } -\keyword{internal} diff --git a/man/nearest_stations_ogimet.Rd b/man/nearest_stations_ogimet.Rd index 6431d4ba..56945755 100644 --- a/man/nearest_stations_ogimet.Rd +++ b/man/nearest_stations_ogimet.Rd @@ -41,10 +41,10 @@ The returned list is valid only for a given day. } \examples{ \donttest{ - nearest_stations_ogimet(country = "Uniced Kingdom", + nearest_stations_ogimet(country = "United Kingdom", point = c(-2, 50), add_map = TRUE, - no_of_stations = 0, + no_of_stations = 50, allow_failure = TRUE, main = "Meteo stations in UK") } diff --git a/man/ogimet_daily.Rd b/man/ogimet_daily.Rd index e2823a36..c2637a7c 100644 --- a/man/ogimet_daily.Rd +++ b/man/ogimet_daily.Rd @@ -23,6 +23,9 @@ ogimet_daily( \item{allow_failure}{logical - whether to proceed or stop on failure. By default set to TRUE (i.e. don't stop on error). For debugging purposes change to FALSE} } +\value{ +data.frame with historical meteorological data for the daily summaries +} \description{ Downloading daily (meteorological) data from the Synop stations available in the https://www.ogimet.com/ repository. The data are processed only if temperature or precipitation fields are present. @@ -34,4 +37,3 @@ The data are processed only if temperature or precipitation fields are present. } } -\keyword{internal} diff --git a/man/ogimet_hourly.Rd b/man/ogimet_hourly.Rd index 08ceac2a..1da7b405 100644 --- a/man/ogimet_hourly.Rd +++ b/man/ogimet_hourly.Rd @@ -23,6 +23,9 @@ ogimet_hourly( \item{allow_failure}{logical - whether to proceed or stop on failure. By default set to TRUE (i.e. don't stop on error). For debugging purposes change to FALSE} } +\value{ +data.frame with historical meteorological data for hourly time interval +} \description{ Downloading hourly (meteorological) data from the Synop stations available in the https://www.ogimet.com/ repository } diff --git a/man/precip_split.Rd b/man/precip_split.Rd deleted file mode 100644 index 14d1db51..00000000 --- a/man/precip_split.Rd +++ /dev/null @@ -1,26 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/precip_split.R -\name{precip_split} -\alias{precip_split} -\title{Splitting precipitation values to 6/12/24 hour periods and converting to numeric} -\usage{ -precip_split(precip, pattern = "/12") -} -\arguments{ -\item{precip}{vector of characters with precipitation field from Ogimet} - -\item{pattern}{6h-12h-24h precipitation pattern to obtain written as: "/6h", "/12h" , "/24h" (see examples)} -} -\description{ -Internal function for splitting precipitation field provided by Ogimet and converting string to numerical value -} -\examples{ -\donttest{ - df = tryCatch(ogimet_hourly(station = 12330), error = function(e) 0) - if (is.data.frame(df)) { - climate:::precip_split(df$Precmm, pattern = "/12") # to get 12h precipitation amounts - } -} - -} -\keyword{internal} diff --git a/man/profile_demo.Rd b/man/profile_demo.Rd index f0ce0833..76cab8c4 100644 --- a/man/profile_demo.Rd +++ b/man/profile_demo.Rd @@ -11,7 +11,7 @@ The data contains list of two data.frames as derived using sounding_wyoming() fu profile_demo } \description{ -The object contains pre-downloaded atmospheric (sounding) profile for Łeba, PL rawinsonde station. +The object contains pre-downloaded atmospheric (sounding) profile for Leba, PL rawinsonde station. The measurement was taken 2000/03/23 at 00 UTC. } \examples{ diff --git a/man/sounding_wyoming.Rd b/man/sounding_wyoming.Rd index 367af8c7..afa33ca9 100644 --- a/man/sounding_wyoming.Rd +++ b/man/sounding_wyoming.Rd @@ -19,7 +19,7 @@ sounding_wyoming( ) } \arguments{ -\item{wmo_id}{international WMO station code (World Meteorological Organization ID); For Polish stations: Łeba - 12120, Legionowo - 12374, Wrocław- 12425} +\item{wmo_id}{international WMO station code (World Meteorological Organization ID); For Polish stations: Leba - 12120, Legionowo - 12374, Wrocław- 12425} \item{yy}{year - single number} @@ -68,11 +68,11 @@ Downloading the measurements of the vertical profile of atmosphere (also known a ############################################################################## TEMP = sounding_wyoming(wmo_id = 45004, yy = 2021, mm = 07, dd = 17, hh = 12, min = 00) - #head(TEMP[[1]]) + head(TEMP[[1]]) BUFR = sounding_wyoming(wmo_id = 45004, yy = 2021, mm = 07, dd = 17, hh = 12, min = 00, bufr = TRUE) - #head(BUFR[[1]]) + head(BUFR[[1]]) ############################################################################## @@ -84,7 +84,6 @@ Downloading the measurements of the vertical profile of atmosphere (also known a mm = sample(1:12,1), dd = sample(1:20,1), hh = 0) - # head(profile) # plot(profile[[1]]$HGHT, profile[[1]]$PRES, type = 'l') } diff --git a/man/spheroid_dist.Rd b/man/spheroid_dist.Rd index 5628e2fe..ce4ba6a3 100644 --- a/man/spheroid_dist.Rd +++ b/man/spheroid_dist.Rd @@ -12,7 +12,7 @@ spheroid_dist(p1, p2) \item{p2}{coordinates of the second point in decimal degrees (LON, LAT)} } \value{ -distance between two locations in kilometers +numerical vector with distance between two locations (in kilometers) } \description{ Calculate the distance between two points on the surface of a spheroid @@ -20,8 +20,8 @@ using Vincenty's formula. This function can be used when GIS libraries for calculating distance are not available. } \examples{ - p1 = c(18.633333, 54.366667) # longitude and latitude for Gdansk - p2 = c(17.016667, 54.466667) # longitude and latitude for Slupsk + p1 = c(18.633333, 54.366667) # longitude and latitude for Gdansk, PL + p2 = c(17.016667, 54.466667) # longitude and latitude for Slupsk, PL spheroid_dist(p1, p2) } diff --git a/man/stations_meteo_imgw_telemetry.Rd b/man/stations_meteo_imgw_telemetry.Rd index 17ca8b88..8cea35d6 100644 --- a/man/stations_meteo_imgw_telemetry.Rd +++ b/man/stations_meteo_imgw_telemetry.Rd @@ -7,7 +7,8 @@ stations_meteo_imgw_telemetry() } \value{ -data table with metadata for over 500 stations. Metadata contains: station ID, station name, river, latitude, longitude, altitude +data table with metadata for over 500 stations. +Metadata contains: station ID, station name, river, latitude, longitude, altitude } \description{ Retrieving current metadata for stations used in the telemetric systems of the IMGW-PIB datastore (danepubliczne.imgw.pl/datastore) diff --git a/man/stations_ogimet.Rd b/man/stations_ogimet.Rd index afb3761c..6a0d0f78 100644 --- a/man/stations_ogimet.Rd +++ b/man/stations_ogimet.Rd @@ -5,18 +5,18 @@ \title{Scrapping a list of meteorological (Synop) stations for a defined country from the Ogimet webpage} \usage{ stations_ogimet( - country = "United+Kingdom", + country = "United Kingdom", date = Sys.Date(), add_map = FALSE, allow_failure = TRUE ) } \arguments{ -\item{country}{country name; for more than two words they need to be separated with a plus character (e.g. "United+Kingdom")} +\item{country}{country name; Every word must be written with capital letters (e.g. "United Kingdom")} \item{date}{a day when measurements were done in all available locations} -\item{add_map}{logical - whether to draw a map with downloaded metadata (requires maps/mapdata packages)} +\item{add_map}{logical - whether to draw a map based on downloaded dataset (requires \code{maps} package)} \item{allow_failure}{logical - whether to proceed or stop on failure. By default set to TRUE (i.e. don't stop on error). For debugging purposes change to FALSE} } @@ -32,5 +32,4 @@ Returns a list of meteorological stations with their coordinates from the Ogimet stations_ogimet(country = "Australia", add_map = TRUE) } - } diff --git a/man/test_url.Rd b/man/test_url.Rd index 44c4ed2a..b0e9db07 100644 --- a/man/test_url.Rd +++ b/man/test_url.Rd @@ -11,11 +11,16 @@ test_url(link, output, quiet = FALSE) \item{output}{character vector for output file name} -\item{quiet}{logical vector (TRUE or FALSE) to be passed to curl_download function. FALSE by default} +\item{quiet}{logical vector (TRUE or FALSE) to be passed to curl_download function. +FALSE by default} +} +\value{ +No return value, called for side effects } \description{ Function for downloading & testing url/internet connection according to CRAN policy -Example solution strongly based on https://community.rstudio.com/t/internet-resources-should-fail-gracefully/49199/12 +Example solution strongly based on +https://community.rstudio.com/t/internet-resources-should-fail-gracefully/49199/12 as suggested by kvasilopoulos } \examples{ diff --git a/tests/testthat/test-hydro_shortening_imgw.R b/tests/testthat/test-hydro_shortening_imgw.R new file mode 100644 index 00000000..1d734a98 --- /dev/null +++ b/tests/testthat/test-hydro_shortening_imgw.R @@ -0,0 +1,19 @@ +test_that("hydro_shortening_imgw", { + + df = structure(list(`Kod stacji` = c(150210180L, 150210180L), + `Nazwa stacji` = c("ANNOPOL", "ANNOPOL"), + `Nazwa rzeki/jeziora` = c("Wisła (2)", "Wisła (2)"), + `Rok hydrologiczny` = c(1969L, 1969L), + `Wskaźnik miesiąca w roku hydrologicznym` = c(1L, 1L), + `Wskaźnik ekstremum` = 1:2, + `Stan wody [cm]` = c(258L, 287L), + `Przepływ [m3/s]` = c(288, 413.266), `Temperatura wody [st. C]` = c(NA_real_, NA_real_), + `Miesiąc kalendarzowy` = c(11L, 11L)), row.names = 7165:7166, class = "data.frame") + + eng_full = hydro_shortening_imgw(data = df, col_names = "full") + eng_short = hydro_shortening_imgw(data = df, col_names = "short") + + expect_true("River_or_Lake" %in% colnames(eng_full)) + expect_true("riv_or_lake" %in% colnames(eng_short)) + +}) \ No newline at end of file diff --git a/vignettes/getstarted.Rmd b/vignettes/getstarted.Rmd index 75fe552d..20e4e3d1 100644 --- a/vignettes/getstarted.Rmd +++ b/vignettes/getstarted.Rmd @@ -14,7 +14,7 @@ knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) -options(scipen = 999) +old <- options(scipen = 999) ``` The goal of the **climate** R package is to automatize downloading of meteorological @@ -237,3 +237,8 @@ library(climate) citation("climate") ``` + + +```{r setup_restore, include = FALSE} +options(old) +```