Skip to content

Commit

Permalink
Merge pull request #1 from SevillaR/master
Browse files Browse the repository at this point in the history
Update from original repo
  • Loading branch information
VictorSuarezL authored Mar 18, 2018
2 parents a7abe77 + a5c9198 commit d178953
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 317 deletions.
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ Type: Package
Title: Obtain Climatic and Meteorological Data from Spanish Meteorological Agency (AEMET)
Version: 0.1.2
Date: 2018-03-17
Authors@R: c(person("Francisco", "Balao", role = "aut"),
Authors@R: c(
person("Francisco", "Rodriguez-Sanchez", email = "[email protected]", role = c("aut", "cre")),
person("Francisco", "Balao", role = "aut"),
person("Francisco", "Viciana", role = "aut"),
person("Pedro", "Molina", role = "aut"),
person("Jose", "Alcaide", role = "aut"),
Expand All @@ -20,7 +21,8 @@ Depends:
R (>= 3.0.0)
Imports:
httr,
jsonlite
jsonlite,
stringr
VignetteBuilder: knitr
RoxygenNote: 6.0.1

3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Generated by roxygen2: do not edit by hand

export(aemet_climatology_station)
export(aemet_stations)
export(dms2decdegrees)
export(get_aemet_normalized)
export(get_data)
import(httr)
importFrom(jsonlite,fromJSON)
importFrom(stringr,str_extract_all)
20 changes: 20 additions & 0 deletions R/aemet_climatology_station.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#' Get normal climatology values for a station
#'
#' Standard climatology from 1981 to 2010.
#'
#' @param station Station identifier code (see \code{\link{aemet_stations}}).
#' @param apikey Personal API key (see \url{https://opendata.aemet.es/centrodedescargas/inicio}).
#'
#' @return a data.frame
#' @export
#'
#' @examples \dontrun{
#' aemet_climatology_station("5911A")
#' }
aemet_climatology_station <- function(station, apikey) {

apidest <- paste0("/api/valores/climatologicos/normales/estacion/", station)

clim <- get_data(apidest, apikey)

}
223 changes: 0 additions & 223 deletions R/get_aemet_mensual.R

This file was deleted.

61 changes: 0 additions & 61 deletions R/get_aemet_normalized.R

This file was deleted.

13 changes: 10 additions & 3 deletions R/get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' @export
#' @import httr
#' @importFrom jsonlite fromJSON
#' @importFrom stringr str_extract_all
#'
#'
get_data <- function(apidest, apikey) {
Expand All @@ -17,8 +18,14 @@ get_data <- function(apidest, apikey) {

path1 <- httr::GET(url1, add_headers(api_key = apikey))

url.data <- httr::content(path1, as = "parsed")$datos
url.metadata <- httr::content(path1, as = "parsed")$metadatos
urls.text <- httr::content(path1, as = "text")

## TO DO: use base R rather than stringr
## Also extract urls more safely
urls <- unlist(stringr::str_extract_all(urls.text,
pattern = "https://opendata.aemet.es/opendata/sh/([:alnum:])+"))
url.data <- urls[1]
url.metadata <- urls[2]

#path2 <- GET(url.data, add_headers(api_key = apikey)) # it seems apikey not necessary for this step
path2 <- httr::GET(url.data)
Expand All @@ -27,4 +34,4 @@ get_data <- function(apidest, apikey) {

datos

}
}
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ To be able to download data from AEMET you will need a free API key which you ca
```{r eval=FALSE}
library(aemet)
stations <- aemet_stations(apikey)
grazalema <- get_aemet_normalized(apikey, "5911A")
grazalema <- aemet_climatology_station("5911A", apikey)
```

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ Usage
``` r
library(aemet)
stations <- aemet_stations(apikey)
grazalema <- get_aemet_normalized(apikey, "5911A")
grazalema <- aemet_climatology_station("5911A", apikey)
```
Loading

0 comments on commit d178953

Please sign in to comment.