Skip to content

Commit

Permalink
Merge pull request #15 from bcgov/update-2023
Browse files Browse the repository at this point in the history
Update 2023
  • Loading branch information
KarHarker committed Dec 21, 2023
2 parents 0d56b22 + 4855f8e commit a730bc1
Show file tree
Hide file tree
Showing 5 changed files with 473 additions and 822 deletions.
33 changes: 22 additions & 11 deletions 01_load.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ if(!dir.exists('tmp'))dir.create('tmp')
## https://www2.gov.bc.ca/gov/content?id=A519A56BC2BF44E4A008B33FCF527F61


# bc_ghg <- read_csv("https://catalogue.data.gov.bc.ca/dataset/24c899ee-ef73-44a2-8569-a0d6b094e60c/resource/11b1da01-fabc-406c-8b13-91e87f126dec/download/bcghg_emissions_1990-2017.csv")
# If pulling in from Data Catalogue, use bcdata() functions below, if pulling from local repo - use lines #38-39

# bc_ghg <- bcdc_get_data(record="24c899ee-ef73-44a2-8569-a0d6b094e60c",
# resource='11b1da01-fabc-406c-8b13-91e87f126dec')
bc_ghg <- bcdc_get_data(record="24c899ee-ef73-44a2-8569-a0d6b094e60c",
resource='11b1da01-fabc-406c-8b13-91e87f126dec')

bc_ghg = read.csv('tmp/bc_ghg_emissions_by_ipcc_sector_1990-2020.csv') |>
as_tibble()
# bc_ghg = read.csv('tmp/bc_ghg_emissions_by_ipcc_sector_1990-2021.csv') |>
# as_tibble()

#If the year columns have had an 'X' added to them... sometimes happens.
colnames(bc_ghg) = gsub(pattern = '^X', replacement = '', x = names(bc_ghg))

# get the most recent year in numeric format
# get the most recent year in numeric format
bc_ghg_yr <- bc_ghg |>
select(max(matches("^20"))) |>
colnames()
Expand All @@ -51,11 +51,11 @@ max_ghg_yr <- as.numeric(bc_ghg_yr)
#bring in economic sector data
# url https://catalogue.data.gov.bc.ca/dataset/british-columbia-greenhouse-gas-emissions/resource/1baa8e16-f1fd-4ea9-9a1d-15f46a5ca066

# ghg_econ <- bcdc_get_data(record='24c899ee-ef73-44a2-8569-a0d6b094e60c',
# resource='1baa8e16-f1fd-4ea9-9a1d-15f46a5ca066')
ghg_econ <- bcdc_get_data(record='24c899ee-ef73-44a2-8569-a0d6b094e60c',
resource='1baa8e16-f1fd-4ea9-9a1d-15f46a5ca066')

ghg_econ = read.csv('tmp/bc_ghg_emissions_by_economic_sector_1990-2020.csv') |>
as_tibble()
# ghg_econ_d = read.csv('tmp/bc_ghg_emissions_by_economic_sector_1990-2021.csv') |>
# as_tibble()

#If the year columns have had an 'X' added to them... sometimes happens.
colnames(ghg_econ) = gsub(pattern = '^X', replacement = '', x = names(ghg_econ))
Expand All @@ -66,7 +66,18 @@ colnames(ghg_econ) = gsub(pattern = '^X', replacement = '', x = names(ghg_econ))
## Data is released under the Statistics Canada Open Licence Agreement
## https://www.statcan.gc.ca/eng/reference/licence)

#add individual gas data
# ghg_gases = read.csv('tmp/bc_ghg_emissions_by_economic_sector_by_gas_1990-2021.csv')

ghg_gases <- bcdc_get_data(record='24c899ee-ef73-44a2-8569-a0d6b094e60c',
resource='99540512-0962-4f51-9bd8-886b6d792b1a')


#If the year columns have had an 'X' added to them... sometimes happens.
colnames(ghg_gases) = gsub(pattern = '^X', replacement = '', x = names(ghg_gases))


#Load BC population data for 1990-2021
bc_pop <- get_cansim(1710000501) |>
filter(GEO == "British Columbia",
REF_DATE >= 1990 & REF_DATE <= max_ghg_yr,
Expand All @@ -90,4 +101,4 @@ bc_pop_gdp <- bc_pop |>
write_csv(bc_pop_gdp, "tmp/bc_ghg_related_data.csv")

# Create tmp folder if not already there and store objects in local repository
save(bc_ghg, bc_pop_gdp, max_ghg_yr, ghg_econ, file = "tmp/raw_data.RData")
save(bc_ghg, bc_pop_gdp, max_ghg_yr, ghg_econ, ghg_gases, file = "tmp/raw_data.RData")
Loading

0 comments on commit a730bc1

Please sign in to comment.