RMI-PACTA / r2dii.usethis

Automate Package And Project Setup
https://2degreesinvesting.github.io/r2dii.usethis
Other
1 stars 2 forks source link

Helper to define dataset columns #17

Closed maurolepore closed 4 years ago

maurolepore commented 4 years ago

I'm not including it in the package to avoid dependencies. I leave this for the record. Closing.

library(magrittr)
define_columns <- function(dataset) {
  usethis::ui_line("#' @format")
  usethis::ui_line("#' `{substitute(dataset)}` is a [data.frame] with columns:")

  r2dii.data::data_dictionary %>% 
    dplyr::filter(.data$dataset == .env$dataset) %>% 
    dplyr::select(-.data$dataset) %>% 
    glue::glue_data("#' * `{column}` ({typeof}): {definition}.")
}

define_columns("ald_demo")
#> #' @format
#> #' `ald_demo` is a [data.frame] with columns:
#> #' * `ald_timestamp` (character): Date at which asset data was pulled from database.
#> #' * `country_of_domicile` (character): Country where company is registered.
#> #' * `emission_factor` (double): Company level emission factor of the technology.
#> #' * `is_ultimate_listed_owner` (logical): Flag if company is the listed ultimate parent.
#> #' * `is_ultimate_owner` (logical): Flag if company is the ultimate parent in our database.
#> #' * `name_company` (character): The name of the company owning the asset.
#> #' * `number_of_assets` (integer): Number of assets of a given technology owned by the company.
#> #' * `plant_location` (character): Country where asset is located.
#> #' * `production` (double): Company level production of the technology.
#> #' * `production_unit` (character): The units that production is measured in.
#> #' * `sector` (character): Sector to which the asset belongs.
#> #' * `technology` (character): Technology implemented by the asset.
#> #' * `year` (integer): Year at which the production value is predicted.

Created on 2020-03-20 by the reprex package (v0.3.0)