Skip to content

Commit

Permalink
handle uppercase spelling of LEI in abcd (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobvjk authored Dec 11, 2024
1 parent 619b9d9 commit 8841fda
Showing 1 changed file with 55 additions and 19 deletions.
74 changes: 55 additions & 19 deletions R/read_.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,60 @@
read_abcd_raw <- function(path, sheet) {
abcd <-
readxl::read_xlsx(
path = file.path(path),
sheet = sheet,
col_types = c(
company_id = "numeric",
name_company = "text",
lei = "text",
is_ultimate_owner = "logical",
sector = "text",
technology = "text",
plant_location = "text",
year = "numeric",
production = "numeric",
production_unit = "text",
emission_factor = "numeric",
emission_factor_unit = "text",
ald_timestamp = "skip"
abcd_names <- readxl::read_xlsx(
path = file.path(path),
sheet = sheet,
col_names = TRUE,
n_max = 0
)
if (
"lei" %in% names(abcd_names)
) {
abcd <-
readxl::read_xlsx(
path = file.path(path),
sheet = sheet,
col_types = c(
company_id = "numeric",
name_company = "text",
lei = "text",
is_ultimate_owner = "logical",
sector = "text",
technology = "text",
plant_location = "text",
year = "numeric",
production = "numeric",
production_unit = "text",
emission_factor = "numeric",
emission_factor_unit = "text",
ald_timestamp = "skip"
)
)
)
} else if (
"LEI" %in% names(abcd_names)
) {
abcd <-
readxl::read_xlsx(
path = file.path(path),
sheet = sheet,
col_types = c(
company_id = "numeric",
name_company = "text",
LEI = "text",
is_ultimate_owner = "logical",
sector = "text",
technology = "text",
plant_location = "text",
year = "numeric",
production = "numeric",
production_unit = "text",
emission_factor = "numeric",
emission_factor_unit = "text",
ald_timestamp = "skip"
)
)
abcd <- dplyr::rename(abcd, lei = "LEI")
} else {
stop("No column 'lei' or 'LEI' found in the data.")
}

dplyr::mutate(abcd, year = as.integer(.data[["year"]]))
}

0 comments on commit 8841fda

Please sign in to comment.