-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: stations_elevation() using read_fwf
- Loading branch information
1 parent
7b4ad57
commit c772735
Showing
8 changed files
with
75 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#' @title The GHCNd Station URL with Elevation | ||
#' @return The URL of the GHCNd stations. | ||
.elevation_url <- function() { | ||
return("https://www.ncei.noaa.gov/pub/data/ghcn/daily/ghcnd-stations.txt") | ||
} | ||
|
||
#' @title Get GHCNd Station Elevation | ||
#' | ||
#' @importFrom readr read_fwf fwf_positions | ||
#' @importFrom curl has_internet | ||
#' | ||
#' @export | ||
#' | ||
#' @return The table with the elevation of GHCNd stations. | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' el <- elevation_stations() | ||
#' } | ||
elevation_stations <- function() { | ||
if (!has_internet()) stop("You do not have access to the internet. Check you connection and try again.") | ||
|
||
ans <- tryCatch( | ||
read_fwf(.elevation_url(), | ||
fwf_positions( | ||
start = c(1, 32), | ||
end = c(11, 38), | ||
col_names = c("station", "elevation") | ||
), | ||
col_types = "cd" | ||
), | ||
error = function(e) message(errorCondition(e)) | ||
) | ||
if (is.null(ans)) stop(.elevation_url(), " not found.") | ||
|
||
return(ans) | ||
|
||
} |
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.