Skip to content

Commit

Permalink
make more generalized function get_ember_data
Browse files Browse the repository at this point in the history
  • Loading branch information
andypicke committed May 3, 2024
1 parent 6d99030 commit a51494a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
export(construct_query_url)
export(get_api_request)
export(get_electricity_generation)
export(get_ember_data)
export(get_ember_options)
4 changes: 1 addition & 3 deletions R/get_electricity_generation.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ get_electricity_generation <- function(temporal_resolution = "yearly",
entity = "all",
api_key = Sys.getenv("EMBER_API_KEY")) {

query_url <- construct_query_url(endpoint = "electricity-generation", temporal_resolution, min_date, max_date, entity, api_key)

df <- get_api_request(query_url)
df <- get_ember_data(dataset = "electricity-generation", temporal_resolution, min_date, max_date, entity, api_key)

return(df)
}
25 changes: 25 additions & 0 deletions R/get_ember_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#' Get Ember-climate data from API
#' @param dataset Dataset to retrieve. Default = "electricity-generation". Other options are "power-sector-emissions", "electricity-demand", and "carbon-intensity"
#' @param temporal_resolution "yearly" (default) or "monthly"
#' @param min_date Mininum date to retrieve data for. YYYY or YYYY-MM format. Default=2015
#' @param max_date Maximum date to retrieve data for. YYYY or YYYY-MM format. Default=2023
#' @param entity List of comma-separated country(s) or region(s) to return data for. Default is all (no filter)
#' @param api_key Default is Sys.getenv("EMBER_API_KEY")
#' @returns df Dataframe of requested data
#' @export
#' @seealso [get_ember_options()]

get_ember_data <- function(dataset = "electricity-generation",
temporal_resolution = "yearly",
min_date = "2015",
max_date = "2023",
entity = "all",
api_key = Sys.getenv("EMBER_API_KEY")) {

query_url <- construct_query_url(endpoint = dataset, temporal_resolution,
min_date, max_date, entity, api_key)

df <- get_api_request(query_url)

return(df)
}
37 changes: 37 additions & 0 deletions man/get_ember_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a51494a

Please sign in to comment.