I am struggling with downloading csv data from the Alberta Electric System Operator site (AESO Site). The data are accessed by completing the form and then clicking the OK radio button.
Here's the code that I'm running.
library(rvest)
library(stringi)
library(tidyverse)
get_metered_volumes_report <- function(start_date, end_date) {
start_date <- as.Date(start_date)
end_date <- as.Date(end_date)
GET(
url = "http://ets.aeso.ca/ets_web/ip/Market/Reports/PublicSummaryAllReportServlet",
query = list(
beginDate = format(start_date, "%m%d%Y"),
endDate = format(end_date, "%m%d%Y"),
contentType = "csv"
)
) -> res
content(res, as="text") %>%
stri_split_lines() %>%
flatten_chr() ->
read.csv(
text = gsub("\"-\",", "",paste(c(paste(test[8:9], collapse=","), test[13:length(test)]), collapse="\n")),
header = TRUE, stringsAsFactors=FALSE
) %>% janitor::clean_names() %>%
tbl_df()
}
xdf <- get_metered_volumes_report("2019-12-12", "2021-01-13")
I'm facing an Error in read.csv(gsub(""-",", "", paste(c(paste(test[8:9], collapse = ","), : target of assignment expands to non-language object Traceback: