From d782c4aab30554f1576eacecb35460e9e0b8cfe1 Mon Sep 17 00:00:00 2001 From: Leon Date: Sun, 13 Mar 2022 15:08:28 -0500 Subject: [PATCH 01/14] added function import_from_emissions --- NAMESPACE | 4 + R/import_from_emissions.R | 92 ++++++++++++++++++ data-raw/db_tables-R.R | 3 + data-raw/db_tables.R | 71 ++++++++++++++ data/db_table_names.rda | Bin 0 -> 749 bytes .../word_documents/word-example.docx | Bin 88492 -> 96679 bytes .../word_documents/wordtemplate.docx | Bin 91632 -> 93758 bytes man/import_from_emissions.Rd | 60 ++++++++++++ 8 files changed, 230 insertions(+) create mode 100644 R/import_from_emissions.R create mode 100644 data-raw/db_tables-R.R create mode 100644 data-raw/db_tables.R create mode 100644 data/db_table_names.rda create mode 100644 man/import_from_emissions.Rd diff --git a/NAMESPACE b/NAMESPACE index 0b35901..d4b405f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,7 @@ export("%>%") export(council.pal) export(council_pal2) export(council_theme) +export(import_from_emissions) export(import_from_gis) export(import_from_gpkg) export(scale_color_council) @@ -11,6 +12,8 @@ export(scale_fill_council) export(snippets_install) export(theme_council) export(theme_council_open) +importFrom(DBI,dbCanConnect) +importFrom(DBI,dbConnect) importFrom(DBI,dbDisconnect) importFrom(DBI,dbGetQuery) importFrom(fs,dir_create) @@ -47,5 +50,6 @@ importFrom(sf,st_transform) importFrom(tictoc,tic) importFrom(tictoc,toc) importFrom(utils,download.file) +importFrom(utils,osVersion) importFrom(utils,tail) importFrom(utils,unzip) diff --git a/R/import_from_emissions.R b/R/import_from_emissions.R new file mode 100644 index 0000000..a3464be --- /dev/null +++ b/R/import_from_emissions.R @@ -0,0 +1,92 @@ +#' Import data table from Emissions Database +#' +#' @param uid character, your network id. +#' Default is `getOption("councilR.uid")`. For example, `"mc\\rotenle"` +#' @param pwd character, your network password. +#' Default is `getOption("councilR.pwd")`. For example, `"my_password"` +#' @param serv character, database server. +#' Default is `"dbsqlcl11t.test.local,65414"` (the test database). +#' @param db character, database name. Default is `"CD_Emissions"` +#' @param table_name character, which table to pull +#' +#' @description WARNING: Function error may results in RStudio crash. Requires a password for access to the database. +#' +#' @note To make connection seamless, add `councilR.uid` and `councilR.pwd` to your `.Rprofile`. Edit your `.Rprofile` as such +#' +#' ``` +#' options( +#' ..., +#' councilR.uid = "mc\\myuid", +#' councilR.pwd = keyring::key_get("MetC") +#' ) +#' ``` +#' See more details in [`{councilR}` documentation](https://github.com/Metropolitan-Council/councilR/blob/main/vignettes/Options.Rmd). +#' +#' @return a table from the CD_Emissions database. +#' @export +#' +#' @examples +#' \dontrun{ +#' library(councilR) +#' +#' # set options if you haven't already +#' options( +#' councilR.uid = "mc\\myuid", +#' councilR.pwd = "mypwd" +#' ) +#' +#' t_electricity_residential_ctu <- import_from_emissions(table_name = "metro_energy.vw_electricity_residential_ctu") +#' t_eia_energy_consumption_state <- import_from_emissions(table_name = "state_energy.eia_energy_consumption_state") +#' t_utility_natural_gas_by_ctu <- import_from_emissions(table_name = "metro_energy.vw_utility_natural_gas_by_ctu") +#' } +#' @importFrom DBI dbCanConnect dbGetQuery dbConnect dbDisconnect +#' @importFrom odbc odbc +#' @importFrom purrr map flatten +#' @importFrom utils osVersion +import_from_emissions <- function(uid = councilR.uid, + pwd = councilR.pwd, + table_name = "metro_energy.vw_electricity_residential_ctu", + local = TRUE, + serv = "dbsqlcl11t.test.local,65414", + db = "CD_Emissions") { + # browser() + # decide which driver to use based on OS + + if (local == FALSE) { + stop("Non-local isn't ready yet!") + } + + drv <- if (grepl("mac", osVersion)) { + "FreeTDS" + } else { + "SQL Server" + } + + # check that DB connection works + if (DBI::dbCanConnect( + odbc::odbc(), + Driver = drv, + Database = db, + Server = serv, + Trusted_Connection = "yes" + ) == FALSE) { + stop("Database failed to connect") + } + + conn <- DBI::dbConnect( + odbc::odbc(), + Driver = drv, + Database = db, + Uid = uid, + Pwd = pwd, + Server = serv, + Trusted_Connection = "yes" + ) + + db_sp_table <- DBI::dbGetQuery(conn, + paste0("SELECT * FROM ", table_name)) + + DBI::dbDisconnect(conn) + + return(db_sp_table) +} diff --git a/data-raw/db_tables-R.R b/data-raw/db_tables-R.R new file mode 100644 index 0000000..8544810 --- /dev/null +++ b/data-raw/db_tables-R.R @@ -0,0 +1,3 @@ +## code to prepare `db_tables.R` dataset goes here + +usethis::use_data(db_tables.R, overwrite = TRUE) diff --git a/data-raw/db_tables.R b/data-raw/db_tables.R new file mode 100644 index 0000000..ba1aee7 --- /dev/null +++ b/data-raw/db_tables.R @@ -0,0 +1,71 @@ +db_table_names <- list( + # mod 1 + mod_1 = list( + "t_ctu_forecast" = "metro_sp_mod_1.vw_ctu_forecast" + ), + + + # mod 2 + mod_2 = list( + "t_ztrax_building_sqft" = "metro_sp_mod_2.vw_ztrax_building_sqft", + "t_ztrax_sqft_summary_ctu" = "metro_sp_mod_2.vw_ztrax_sqft_summary_ctu", + "t_ztrax_sqft_summary_county" = "metro_sp_mod_2.ztrax_sqft_summary_county" + ), + + # mod 3 + mod_3 = list( + "aeo_factor" = "metro_sp_mod_3.aeo_factor", + "aeo_scenario" = "metro_sp_mod_3.aeo_scenario", + "cost_factor" = "metro_sp_mod_3.cost_factor", + "ghg_factor" = "metro_sp_mod_3.ghg_factor", + "mode" = "metro_sp_mod_3.mode", + "pass_transpo" = "metro_sp_mod_3.pass_transpo", + "sources" = "metro_sp_mod_3.sources", + "variables" = "metro_sp_mod_3.variables" + ), + + # metro demos + metro_demos = list( + "t_ctu_population" = "metro_demographic.vw_ctu_population", + "t_ctu_qcew_ctu" = "metro_demographic.vw_qcew_ctu", + "t_ctu_county" = "metro_demographic.vw_ctu_county", + "t_housing_stock_ctu" = "metro_demographic.vw_housing_stock_ctu", + "t_emp_forecast_county" = "metro_demographic.vw_emp_forecast_county", + "t_emp_forecast_ctu" = "metro_demographic.vw_emp_forecast_ctu", + "t_led_industry_county" = "metro_demographic.vw_led_industry_county" + ), + + + # state demos + state_demos = list( + "t_county" = "state_demographic.county", + "t_state_qcew" = "state_demographic.vw_state_qcew" + ), + + # metro energy + metro_energy = list( + "t_electricity_residential_ctu" = " metro_energy.vw_electricity_residential_ctu", + "t_natural_gas_residential_ctu" = "metro_energy.vw_natural_gas_residential_ctu", + "t_intersect_landuse_utility_service_area_ctu" ="metro_energy.vw_intersect_landuse_utility_service_area_ctu", + "t_utility_electricity_by_ctu" = "metro_energy.vw_utility_electricity_by_ctu", + "t_eia_electricity_servicewide" = "metro_energy.vw_eia_electricity_servicewide", + "t_mndoc_electricity_county" = "metro_energy.vw_mndoc_electricity_county", + "t_intersect_landuse_utility_service_area_county" = "metro_energy.vw_intersect_landuse_utility_service_area_county", + "t_nrel_energy_consumption_ctu" = "metro_energy.vw_nrel_energy_consumption_ctu", + "t_utility_natural_gas_by_ctu" = "metro_energy.vw_utility_natural_gas_by_ctu" + ), + + # state energy + state_energy = list( + "t_eia_energy_consumption_state" = "state_energy.eia_energy_consumption_state" + ) +) + +usethis::use_data(db_table_names, overwrite = T) + + +# db tables----- + +db_tables <- fetch_db_tables(module = "all") + +usethis::use_data(db_tables, overwrite = T) diff --git a/data/db_table_names.rda b/data/db_table_names.rda new file mode 100644 index 0000000000000000000000000000000000000000..f470c30d650e5a36d8292bded8dc60d806d7a1a8 GIT binary patch literal 749 zcmVG#NQ^Jj=pay`@00000X^={2g*2X{A*ZMS0001bjG8n6 z=8Tw_0GNyj(*g`e36lVf3X)AsnoI=APf+xM z#?nN{CNylr3_%eaIVTd=e~}cW zB9wX*n1p3*GbEx3mJt;W=}w6-Tqb-@PVZUv6bh$&cSvL@6F!CSRg&y2eYIJvlub>> z)_QKS{%KzYYAVXBAMt8?6W7kYH#^O4lF~jC$#;po=Ic$c&54?O-E*Ne!>PqAa%A!_ zMusOJvaJ(InozWfqDg1lY^tv!jg5n2YMYBi>A2jAFh-fO>kOn(l7hy=FwD(3<*Lp(aD5Ay;7XL#O~$JrJ`zMmsvaN5nn|GWOmVu7$6@AND7ywG1{+1 zDwa(P8d@0~OC}}_f8EKcNu*}8tI_A*qwZIQg;W-B7O}_hsKiSJIYg7@$K$PBWda)n^QRN fqN*trqOmHrN~;q&rk=QaVE-3#ML1B9i5`JOLsnNQ literal 0 HcmV?d00001 diff --git a/inst/rmarkdown/templates/word_documents/word-example.docx b/inst/rmarkdown/templates/word_documents/word-example.docx index 00177293da70bbec7a7da59e095ee3df9a5615fe..01963755285284136b1aad75ffcaf781f333642e 100644 GIT binary patch delta 10154 zcmd^F2UJwaw(TYe3X*eZvNT8r$w(9=ibM&G2sA;-S<;o95hN)&svtQ_6c_{~N*u{Z z5F}>-h2Q8PVP?IV_tw1s{(ArRs@1pqR_#-FpQ>|CovNH-)E675fU-O?$|cZ`iw1Ov zxGKOP&{4rb{HbGad(X}k#?FDb*o^MkA3guA^563X{5>%LGRl8izQw=X^MAJCk)mU9 z)xc!MC`cRRz*(KEBJ_P!&gq=<-=g!Qp8uzL|4+*=wx^P&Kc@sXgaVGrIVEuY*D68# zpB=-0y?!y?4K}26{L&z}Ju2t;<^HebSMjg&^%rV-2j46Yz6ln`0FY4#Ko>yhh&D7J zmJuS9ax}z*z5)W_gP}K|G3r;p?3v=o;dJr^)`cFl)YirpJ^Wu1P zDI6gCyO+J}E#kS&6&6*J)OxLOXkO<6l33uiiyZW(K-*z0h8KwaJ*`=JKyhaD)}Tko8SylRS&Yws?T`JikqloG`jD#oE&9;{N+OL*dj`%4R&R$-i4%vmg+ zX(EI@S8M_}pd+xkuXzMH0e0Omsf&t0C1gvMC6)Z~JYj7{11ku@W~w~@P+HuHKk z#E+f0`8z)ru9NuE1ei@fbao~YR=6NMB;O+4Ii4)aWYx=0IkjyfX;+@O)M!%z@d1@rb;y>v86cIJ z??o!MKDDRTBMWa6PSGPRU@pZ$7z0Jq?g#_H^%ojkgO{NT4&NMTzYr}=S^km?9S&~1 zT$PE_m_cXbH#E4lV;O5~U#BWfM;|#nfML|<(EPPgq@te+dOb%#ptU|ifQ}p3+X-^Y z=;BHaXM1wMR;lNj#sj<0_drfH_v71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x95P1XgHpBDLZ_ZNFPduhA<`nhvwfhy$MAxaLWX^u6zTQ( zm#G*T+gUjKKxQ)9A=A8a!C%eX_8%s;pTp=WfF`1v)_U8%v`Q_|&{A)))YoMr%l6l% zl(M%DO0!g<`cO3W1!b3ksN$h$WUi|+_(mAH-LaLz*Kjti={GwrcF;EgS*Lzcc&?Wa+1`j5EQP;;|Sweue`5u-%d{h!Kf0g@w-&P(Cp@dKn%dYvY zA$%*3KfP*l_KicukgXApiIV5|ZW52uy}Ih{o4Xb09v?<=!rQ4goJgHF{Wl900v{Xg zZ_PS67?gXTm5856pDlH#Nc+T$(50ac>c`NUSI=W#o_m!TX%gCGgiKZnsV@rGFCVBZ zsmT?hZiZ#vnd2a8Ga_!st$Nd3M`cpTu3poikhg#4KDPD1aj%r>ecSv+or#Kj<5q4*to7rvu zZi2E_K&;4G05(ue$tp3T*X> z9qa$h1Q(}mg6wx77K(}hmAB99Ff7E60M+;JB>twm>>yoM{-f96rFNP_SO)m7zuyEf zK!a`iQ4$uaVSwM*zy9BAr4<&^kNn2@U%zb&FT2Av0MuFo&^immK|BU10To7q`dT}~ z_)A{!KZoL1teG8jE)>K-E^#2@PcV)N#%{;g=!%8zFu{QB^YBq@oo*EP3n(YPYa6Su PwV#Lsz$5o9%>w@gt)d)w diff --git a/inst/rmarkdown/templates/word_documents/wordtemplate.docx b/inst/rmarkdown/templates/word_documents/wordtemplate.docx index fc0d27c3c956be77c4a39b17635cb9c1ed562e7e..c947cdca9113819fbfad480bb208aa9a2e516cfa 100644 GIT binary patch delta 3725 zcmZ`+2Qb`S_uiixA&4NWcUE7bThS6;qL)Nl!Ro#DwOB;&tlmWkiC#9MM)VRjdPEPK z;Ej?9{*w2bdH*xteCN({=gv7Zcjnx4?wRK~7$)pkA`EQ=X85^Lamu~jAP|Th0D#z3LY2H?o}X*TI-}*Uhy*FRM1T& zuQpJ!vTPFS*eEMN%DgF)X9+KY)&&F#PT_0S1u*m@7*FOu$+~e0@>|I8$`i zQDh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g)JIaY#^x!HL?d8W!-5LgbURU_N`Qvp0KpRbGpv z#0~olt1;+lsMS=hI>A%~(=*f0`ZFHnz=0t4znF9y`MZT!+x_M~gB+Hjhk?Jbg?mA1l>GOD486*niAEp^+P%}|=`&}~;fzedB+#VTGOZkXM{0SA%z zb<8Ivy8uj|g2zX84Dn%{Eg7gCr6Mn6rBBn7ca_$Vdn1 zKWPl-Y}s^}IGXF-vV~8?(#evp)v=5oD7WfnoJPAR02O--hmRs-oU*p)9wmNZGptvv zbi2|iWMxKfb3=au?Nr|M7_HLR4=GJXDD6>F6_9E_D}F5O+gkem!Y4khQjbu>-&<%U zX~iDQxAG|JXZ0_mMAHXZvgn#xhp3|PY6+DCWB>Am~WERX4VtLq$^@Dx#sigku|cqe z{WajFhINIMAk&51>4szNiP$(xwY$@dVee{-(UcW*CCjL zXrkpLk1dU5Cz+hR9%{I$%|y~V8o>_r4_FMX{3xsKjo$g$R1(SR4+`69Dh)75b9>9H zl;j*-{t|5_JYI_?`_|pU2jOc)9Ic#5^@{!TS1`w}KpI^217Hp{&dw1?dxh%1a*7Fb z2KxP5eomZ$l8Ouf3IOG$CvgG(8?gU=^M5b667c_|_V(WdFpe(3Ngx5E<_h#D|A!ck Z;0hEXV<4ya`!v^O#b35Ivblr^_z%wgPdxwt diff --git a/man/import_from_emissions.Rd b/man/import_from_emissions.Rd new file mode 100644 index 0000000..234b7e9 --- /dev/null +++ b/man/import_from_emissions.Rd @@ -0,0 +1,60 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/import_from_emissions.R +\name{import_from_emissions} +\alias{import_from_emissions} +\title{Import data table from Emissions Database} +\usage{ +import_from_emissions( + uid = councilR.uid, + pwd = councilR.pwd, + table_name = "metro_energy.vw_electricity_residential_ctu", + local = TRUE, + serv = "dbsqlcl11t.test.local,65414", + db = "CD_Emissions" +) +} +\arguments{ +\item{uid}{character, your network id. +Default is \code{getOption("councilR.uid")}. For example, \code{"mc\\\\rotenle"}} + +\item{pwd}{character, your network password. +Default is \code{getOption("councilR.pwd")}. For example, \code{"my_password"}} + +\item{table_name}{character, which table to pull} + +\item{serv}{character, database server. +Default is \code{"dbsqlcl11t.test.local,65414"} (the test database).} + +\item{db}{character, database name. Default is \code{"CD_Emissions"}} +} +\value{ +a table from the CD_Emissions database. +} +\description{ +WARNING: Function error may results in RStudio crash. Requires a password for access to the database. +} +\note{ +To make connection seamless, add \code{councilR.uid} and \code{councilR.pwd} to your \code{.Rprofile}. Edit your \code{.Rprofile} as such\preformatted{options( + ..., + councilR.uid = "mc\\\\myuid", + councilR.pwd = keyring::key_get("MetC") +) +} + +See more details in \href{https://github.com/Metropolitan-Council/councilR/blob/main/vignettes/Options.Rmd}{\code{{councilR}} documentation}. +} +\examples{ +\dontrun{ +library(councilR) + +# set options if you haven't already +options( + councilR.uid = "mc\\\\myuid", + councilR.pwd = "mypwd" +) + +t_electricity_residential_ctu <- import_from_emissions(table_name = "metro_energy.vw_electricity_residential_ctu") +t_eia_energy_consumption_state <- import_from_emissions(table_name = "state_energy.eia_energy_consumption_state") +t_utility_natural_gas_by_ctu <- import_from_emissions(table_name = "metro_energy.vw_utility_natural_gas_by_ctu") +} +} From 57cd67f00213baa501871a00c180088cb0f71b93 Mon Sep 17 00:00:00 2001 From: Leon Date: Mon, 14 Mar 2022 14:26:39 -0500 Subject: [PATCH 02/14] removed unnecesary scripts --- data-raw/db_tables-R.R | 3 -- data-raw/db_tables.R | 71 ------------------------------------------ 2 files changed, 74 deletions(-) delete mode 100644 data-raw/db_tables-R.R delete mode 100644 data-raw/db_tables.R diff --git a/data-raw/db_tables-R.R b/data-raw/db_tables-R.R deleted file mode 100644 index 8544810..0000000 --- a/data-raw/db_tables-R.R +++ /dev/null @@ -1,3 +0,0 @@ -## code to prepare `db_tables.R` dataset goes here - -usethis::use_data(db_tables.R, overwrite = TRUE) diff --git a/data-raw/db_tables.R b/data-raw/db_tables.R deleted file mode 100644 index ba1aee7..0000000 --- a/data-raw/db_tables.R +++ /dev/null @@ -1,71 +0,0 @@ -db_table_names <- list( - # mod 1 - mod_1 = list( - "t_ctu_forecast" = "metro_sp_mod_1.vw_ctu_forecast" - ), - - - # mod 2 - mod_2 = list( - "t_ztrax_building_sqft" = "metro_sp_mod_2.vw_ztrax_building_sqft", - "t_ztrax_sqft_summary_ctu" = "metro_sp_mod_2.vw_ztrax_sqft_summary_ctu", - "t_ztrax_sqft_summary_county" = "metro_sp_mod_2.ztrax_sqft_summary_county" - ), - - # mod 3 - mod_3 = list( - "aeo_factor" = "metro_sp_mod_3.aeo_factor", - "aeo_scenario" = "metro_sp_mod_3.aeo_scenario", - "cost_factor" = "metro_sp_mod_3.cost_factor", - "ghg_factor" = "metro_sp_mod_3.ghg_factor", - "mode" = "metro_sp_mod_3.mode", - "pass_transpo" = "metro_sp_mod_3.pass_transpo", - "sources" = "metro_sp_mod_3.sources", - "variables" = "metro_sp_mod_3.variables" - ), - - # metro demos - metro_demos = list( - "t_ctu_population" = "metro_demographic.vw_ctu_population", - "t_ctu_qcew_ctu" = "metro_demographic.vw_qcew_ctu", - "t_ctu_county" = "metro_demographic.vw_ctu_county", - "t_housing_stock_ctu" = "metro_demographic.vw_housing_stock_ctu", - "t_emp_forecast_county" = "metro_demographic.vw_emp_forecast_county", - "t_emp_forecast_ctu" = "metro_demographic.vw_emp_forecast_ctu", - "t_led_industry_county" = "metro_demographic.vw_led_industry_county" - ), - - - # state demos - state_demos = list( - "t_county" = "state_demographic.county", - "t_state_qcew" = "state_demographic.vw_state_qcew" - ), - - # metro energy - metro_energy = list( - "t_electricity_residential_ctu" = " metro_energy.vw_electricity_residential_ctu", - "t_natural_gas_residential_ctu" = "metro_energy.vw_natural_gas_residential_ctu", - "t_intersect_landuse_utility_service_area_ctu" ="metro_energy.vw_intersect_landuse_utility_service_area_ctu", - "t_utility_electricity_by_ctu" = "metro_energy.vw_utility_electricity_by_ctu", - "t_eia_electricity_servicewide" = "metro_energy.vw_eia_electricity_servicewide", - "t_mndoc_electricity_county" = "metro_energy.vw_mndoc_electricity_county", - "t_intersect_landuse_utility_service_area_county" = "metro_energy.vw_intersect_landuse_utility_service_area_county", - "t_nrel_energy_consumption_ctu" = "metro_energy.vw_nrel_energy_consumption_ctu", - "t_utility_natural_gas_by_ctu" = "metro_energy.vw_utility_natural_gas_by_ctu" - ), - - # state energy - state_energy = list( - "t_eia_energy_consumption_state" = "state_energy.eia_energy_consumption_state" - ) -) - -usethis::use_data(db_table_names, overwrite = T) - - -# db tables----- - -db_tables <- fetch_db_tables(module = "all") - -usethis::use_data(db_tables, overwrite = T) From bf31df3e3588bdfb967d47a167446254601732dd Mon Sep 17 00:00:00 2001 From: Liz Roten Date: Tue, 15 Mar 2022 11:22:03 -0500 Subject: [PATCH 03/14] create emissions_db_table_names db_table_names is too vague in this context --- data-raw/emissions_db_table_names.R | 68 ++++++++++++++++++++++++++++ data/emissions_db_table_names.rda | Bin 0 -> 758 bytes 2 files changed, 68 insertions(+) create mode 100644 data-raw/emissions_db_table_names.R create mode 100644 data/emissions_db_table_names.rda diff --git a/data-raw/emissions_db_table_names.R b/data-raw/emissions_db_table_names.R new file mode 100644 index 0000000..21db36f --- /dev/null +++ b/data-raw/emissions_db_table_names.R @@ -0,0 +1,68 @@ +## code to prepare `emissions_db_table_names` dataset goes here + + +emissions_db_table_names <- list( + # mod 1 + mod_1 = list( + "t_ctu_forecast" = "metro_sp_mod_1.vw_ctu_forecast" + ), + + + # mod 2 + mod_2 = list( + "t_ztrax_building_sqft" = "metro_sp_mod_2.vw_ztrax_building_sqft", + "t_ztrax_sqft_summary_ctu" = "metro_sp_mod_2.vw_ztrax_sqft_summary_ctu", + "t_ztrax_sqft_summary_county" = "metro_sp_mod_2.ztrax_sqft_summary_county" + ), + + # mod 3 + mod_3 = list( + "aeo_factor" = "metro_sp_mod_3.aeo_factor", + "aeo_scenario" = "metro_sp_mod_3.aeo_scenario", + "cost_factor" = "metro_sp_mod_3.cost_factor", + "ghg_factor" = "metro_sp_mod_3.ghg_factor", + "mode" = "metro_sp_mod_3.mode", + "pass_transpo" = "metro_sp_mod_3.pass_transpo", + "sources" = "metro_sp_mod_3.sources", + "variables" = "metro_sp_mod_3.variables" + ), + + # metro demos + metro_demos = list( + "t_ctu_population" = "metro_demographic.vw_ctu_population", + "t_ctu_qcew_ctu" = "metro_demographic.vw_qcew_ctu", + "t_ctu_county" = "metro_demographic.vw_ctu_county", + "t_housing_stock_ctu" = "metro_demographic.vw_housing_stock_ctu", + "t_emp_forecast_county" = "metro_demographic.vw_emp_forecast_county", + "t_emp_forecast_ctu" = "metro_demographic.vw_emp_forecast_ctu", + "t_led_industry_county" = "metro_demographic.vw_led_industry_county" + ), + + + # state demos + state_demos = list( + "t_county" = "state_demographic.county", + "t_state_qcew" = "state_demographic.vw_state_qcew" + ), + + # metro energy + metro_energy = list( + "t_electricity_residential_ctu" = " metro_energy.vw_electricity_residential_ctu", + "t_natural_gas_residential_ctu" = "metro_energy.vw_natural_gas_residential_ctu", + "t_intersect_landuse_utility_service_area_ctu" = "metro_energy.vw_intersect_landuse_utility_service_area_ctu", + "t_utility_electricity_by_ctu" = "metro_energy.vw_utility_electricity_by_ctu", + "t_eia_electricity_servicewide" = "metro_energy.vw_eia_electricity_servicewide", + "t_mndoc_electricity_county" = "metro_energy.vw_mndoc_electricity_county", + "t_intersect_landuse_utility_service_area_county" = "metro_energy.vw_intersect_landuse_utility_service_area_county", + "t_nrel_energy_consumption_ctu" = "metro_energy.vw_nrel_energy_consumption_ctu", + "t_utility_natural_gas_by_ctu" = "metro_energy.vw_utility_natural_gas_by_ctu" + ), + + # state energy + state_energy = list( + "t_eia_energy_consumption_state" = "state_energy.eia_energy_consumption_state" + ) +) + + +usethis::use_data(emissions_db_table_names, overwrite = TRUE) diff --git a/data/emissions_db_table_names.rda b/data/emissions_db_table_names.rda new file mode 100644 index 0000000000000000000000000000000000000000..200e103afdbefa0bc8b8075f5cddc75ef7f23509 GIT binary patch literal 758 zcmVT4*^jL0KkKS=0T5m;eGL|A7AeTYt-axDo^a5J120|L_0-&;xnA!~>wC z2~|BN2mk?~&;g(T0K~&kK~u_jQ1v}PXaE2hLqi|{0K!u#l*#E0Gynhq06j)c88m2f zModfqOhyE0fd(T4$$&-$NhX47Vriy{sCrEd%56q~4F-cjwHHKIQUsQ*w>xA&fZJ`b zPAphmHPJ%z!=IZU?d5eqwUOFDQCoC_0DxR6R`S!EOaMj31klkW;G#lQf=bXLAOZ>@ z00zp_sk9QhDn7HAn#L08FvcsnU~#FPFDklgEC{u%-_ViS5mbbvh*YYR3n7IfBiF{s z69Gh@WkJzCDr7tA0w^Rx4$7{18M4h}_30qiN&_PIHOP z%uYcBDbC#`B}D>a_=u=Bl%|maksa$&iuePgV$wbx8 zZ*0=*9^DtgT9sv0kMOlWwElXl)pNYs=`ADRJXd>;2UD>(!($_2c{?XEZHHTmSme#( zV2oKDeyX%h4T(b1CNfJcY^tpyjjf|=a+}LV>Ac>GFh-MY)*pV7ENGyyxYRW@PC4^h zt*L@ZWY|s#;@Dtr>){Q7$;ufzOS#Qq)R+#(LE6Y@%nLSndgyciZIN5#(!92lGyFiR%`ne#%D%*&^#nZz#0 zQj$v|tg2ZtS&cMg%;H%yFkf%)i8NAZ<4LOrU#Gg1YXso|EGthChmj$OAVZlE6igVB z`(VCiNwdKs*}R=Qq3=VG>K1v+x28||EIi32){!zaN#zfYMEjbv9%Pp(-cp-KyU*xK oBYEp0o6}@>(Nz?RQCSsRrB#Dbr4OP8Qh&wVkxmpOH2+~H0Op}qwEzGB literal 0 HcmV?d00001 From 1c6ebf176b72e3ddf2c78fed82dff8d885053c3a Mon Sep 17 00:00:00 2001 From: Liz Roten Date: Tue, 15 Mar 2022 11:23:03 -0500 Subject: [PATCH 04/14] delete db_table_names all items in data/ must be added by `usethis::use_data()` from a script in data-raw/ --- data/db_table_names.rda | Bin 749 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 data/db_table_names.rda diff --git a/data/db_table_names.rda b/data/db_table_names.rda deleted file mode 100644 index f470c30d650e5a36d8292bded8dc60d806d7a1a8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 749 zcmVG#NQ^Jj=pay`@00000X^={2g*2X{A*ZMS0001bjG8n6 z=8Tw_0GNyj(*g`e36lVf3X)AsnoI=APf+xM z#?nN{CNylr3_%eaIVTd=e~}cW zB9wX*n1p3*GbEx3mJt;W=}w6-Tqb-@PVZUv6bh$&cSvL@6F!CSRg&y2eYIJvlub>> z)_QKS{%KzYYAVXBAMt8?6W7kYH#^O4lF~jC$#;po=Ic$c&54?O-E*Ne!>PqAa%A!_ zMusOJvaJ(InozWfqDg1lY^tv!jg5n2YMYBi>A2jAFh-fO>kOn(l7hy=FwD(3<*Lp(aD5Ay;7XL#O~$JrJ`zMmsvaN5nn|GWOmVu7$6@AND7ywG1{+1 zDwa(P8d@0~OC}}_f8EKcNu*}8tI_A*qwZIQg;W-B7O}_hsKiSJIYg7@$K$PBWda)n^QRN fqN*trqOmHrN~;q&rk=QaVE-3#ML1B9i5`JOLsnNQ From 4a18ab641a5c5ffa4448bd58fefc324a68a57744 Mon Sep 17 00:00:00 2001 From: Liz Roten Date: Tue, 15 Mar 2022 11:26:58 -0500 Subject: [PATCH 05/14] write documentation for emissions_db_table_names --- R/emissions_db_table_names.R | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 R/emissions_db_table_names.R diff --git a/R/emissions_db_table_names.R b/R/emissions_db_table_names.R new file mode 100644 index 0000000..e9b23f6 --- /dev/null +++ b/R/emissions_db_table_names.R @@ -0,0 +1,20 @@ +#' @title Emissions database table names +#' +#' @format Nested, named list of table names available in the CD_Emissions database +#' \describe{ +#' \item{mod_1}{named list of 1 table name} +#' \item{mod_2}{named list of 3 table names} +#' \item{mod_3}{named list of 8 table names } +#' \item{metro_demos}{named list of 7 table names} +#' \item{state_demos}{named list of 2 table names} +#' \item{metro_energy}{named list of 9 table names} +#' \item{state_energy}{named list of 1 table name} +#' } +#' +#' @family datasets +#' @examples +#' library(ghg.sp) +#' emissions_db_table_names$mod_1 +#' emissions_db_table_names$metro_demos +# emissions_db_table_names ----- +"emissions_db_table_names" From 9ecd0a91fe9a965140df11e167e34f80fc858138 Mon Sep 17 00:00:00 2001 From: Liz Roten Date: Tue, 15 Mar 2022 11:30:28 -0500 Subject: [PATCH 06/14] use more recent iteration of function; update documentation --- R/import_from_emissions.R | 110 ++++++++++++++++++++++++-------------- 1 file changed, 69 insertions(+), 41 deletions(-) diff --git a/R/import_from_emissions.R b/R/import_from_emissions.R index a3464be..acc8a3d 100644 --- a/R/import_from_emissions.R +++ b/R/import_from_emissions.R @@ -1,4 +1,4 @@ -#' Import data table from Emissions Database +#' @title Fetch Greenhouse gas scenario planning data tables #' #' @param uid character, your network id. #' Default is `getOption("councilR.uid")`. For example, `"mc\\rotenle"` @@ -7,22 +7,20 @@ #' @param serv character, database server. #' Default is `"dbsqlcl11t.test.local,65414"` (the test database). #' @param db character, database name. Default is `"CD_Emissions"` -#' @param table_name character, which table to pull +#' @param module character, which module tables to pull. One of `"mod_1"`, `"mod_2"`, +#' `"mod_3"`,` "metro_demos"`, +#' `"state_demos"`, `"metro_energy"`, `"state_energy"`, or `"all"` #' -#' @description WARNING: Function error may results in RStudio crash. Requires a password for access to the database. +#' @description WARNING: Function error may results in RStudio crash. #' -#' @note To make connection seamless, add `councilR.uid` and `councilR.pwd` to your `.Rprofile`. Edit your `.Rprofile` as such +#' @note See `vignette("Options")` to review package options. +#' You must be set up with the appropriate database drivers to use this function. +#' **Windows** users need ODBC with Microsoft SQL. Contact IS support for ODBC installation. +#' **Mac** users need `unixodbc` and `freetds`. See instructions in +#' [`{MetroTransitR}`](https://github.com/Metropolitan-Council/MetroTransitR) #' -#' ``` -#' options( -#' ..., -#' councilR.uid = "mc\\myuid", -#' councilR.pwd = keyring::key_get("MetC") -#' ) -#' ``` -#' See more details in [`{councilR}` documentation](https://github.com/Metropolitan-Council/councilR/blob/main/vignettes/Options.Rmd). -#' -#' @return a table from the CD_Emissions database. +#' @return a list of tables from the CD_Emissions database. List length depends +#' `module` parameter. #' @export #' #' @examples @@ -35,20 +33,30 @@ #' councilR.pwd = "mypwd" #' ) #' -#' t_electricity_residential_ctu <- import_from_emissions(table_name = "metro_energy.vw_electricity_residential_ctu") -#' t_eia_energy_consumption_state <- import_from_emissions(table_name = "state_energy.eia_energy_consumption_state") -#' t_utility_natural_gas_by_ctu <- import_from_emissions(table_name = "metro_energy.vw_utility_natural_gas_by_ctu") +#' mod_1_tables <- import_from_emissions(module = "mod_1") +#' mod_2_tables <- import_from_emissions(module = "mod_2") +#' mod_3_tables <- import_from_emissions(module = "mod_3") +#' +#' # or fetch all tables +#' +#' all <- import_from_emissions(module = "all") #' } +#' #' @importFrom DBI dbCanConnect dbGetQuery dbConnect dbDisconnect #' @importFrom odbc odbc #' @importFrom purrr map flatten #' @importFrom utils osVersion -import_from_emissions <- function(uid = councilR.uid, - pwd = councilR.pwd, - table_name = "metro_energy.vw_electricity_residential_ctu", - local = TRUE, - serv = "dbsqlcl11t.test.local,65414", - db = "CD_Emissions") { +import_from_emissions <- function(uid = getOption("councilR.uid"), + pwd = getOption("councilR.pwd"), + module = c( + "mod_1", "mod_2", "mod_3", + "metro_demos", "state_demos", + "metro_energy", "state_energy", + "all" + ), + local = TRUE, + serv = "dbsqlcl11t.test.local,65414", + db = "CD_Emissions") { # browser() # decide which driver to use based on OS @@ -63,30 +71,50 @@ import_from_emissions <- function(uid = councilR.uid, } # check that DB connection works - if (DBI::dbCanConnect( - odbc::odbc(), - Driver = drv, - Database = db, - Server = serv, - Trusted_Connection = "yes" - ) == FALSE) { + if ( + DBI::dbCanConnect( + odbc::odbc(), + Driver = drv, + Database = db, + Uid = uid, + Pwd = pwd, + Server = serv + ) == FALSE) { stop("Database failed to connect") } - conn <- DBI::dbConnect( - odbc::odbc(), - Driver = drv, - Database = db, - Uid = uid, - Pwd = pwd, - Server = serv, - Trusted_Connection = "yes" + + tables_to_fetch <- if (module == "all") { + purrr::flatten(emissions_db_table_names) + } else { + emissions_db_table_names[[module]] + } + + if (length(tables_to_fetch) == 0) { + stop("No matching module name") + } + + conn <- DBI::dbConnect(odbc::odbc(), + Driver = drv, + Database = db, + Uid = uid, + Pwd = pwd, + Server = serv + ) + + db_sp_tables <- purrr::map( + tables_to_fetch, + function(x) { + DBI::dbGetQuery( + conn, + paste0("SELECT * FROM ", x) + ) + } ) - db_sp_table <- DBI::dbGetQuery(conn, - paste0("SELECT * FROM ", table_name)) + names(db_sp_tables) <- names(tables_to_fetch) DBI::dbDisconnect(conn) - return(db_sp_table) + return(db_sp_tables) } From b77296f95e529aea07fc700be8e64fcc414e7f3c Mon Sep 17 00:00:00 2001 From: Liz Roten Date: Tue, 15 Mar 2022 11:35:41 -0500 Subject: [PATCH 07/14] write tests for import_from_emissions() --- tests/testthat/test-import_from_emissions.R | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/testthat/test-import_from_emissions.R diff --git a/tests/testthat/test-import_from_emissions.R b/tests/testthat/test-import_from_emissions.R new file mode 100644 index 0000000..c8d0983 --- /dev/null +++ b/tests/testthat/test-import_from_emissions.R @@ -0,0 +1,28 @@ +# basic testing + +testthat::expect_error( + fetch_db_tables( + local = FALSE, + module = "mod_1" + ) +) + + +# skip on GH Actions +testthat::skip_on_ci() + +# skip if not connected to VPN +testthat::skip_if( + is.null(curl::nslookup("mc.local")) +) + +# skip if "councilR.uid" option() is not set +testthat::skip_if(is.null(getOption("councilR.uid"))) +testthat::skip_if(is.null(getOption("councilR.pwd"))) + + +mod_2 <- fetch_db_tables( + module = "mod_2" +) + +testthat::expect_equal(length(mod_2), 3) From 8f62d7654a6d88892b44cf0825af5c4db33befc4 Mon Sep 17 00:00:00 2001 From: Liz Roten Date: Tue, 15 Mar 2022 11:41:07 -0500 Subject: [PATCH 08/14] increment date, version; add BugReports, URL, testthat edition --- DESCRIPTION | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f305b61..43f2ce9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: councilR Title: Functions and Templates for the Metropolitan Council -Version: 0.1.1.9000 -Date: 2022-03-11 +Version: 0.1.2 +Date: 2022-03-15 Authors@R: c( person("Metropolitan Council", role = "cph"), person("Liz", "Roten", , "liz.roten@metc.state.mn.us", role = c("cre", "aut"), @@ -15,6 +15,7 @@ Authors@R: c( Description: A collection of commonly used templates, color palettes, functions, and more! License: MIT + file LICENSE +BugReports: https://github.com/Metropolitan-Council/councilR/issues Depends: R (>= 2.10) Imports: @@ -39,7 +40,7 @@ Suggests: repmis (>= 0.5), rmarkdown (>= 2.11), stringr (>= 1.4.0), - testthat (>= 2.3.2), + testthat (>= 3.0.0), tibble (>= 3.1.6), usethis (>= 1.6.1) Enhances: @@ -49,7 +50,9 @@ VignetteBuilder: knitr Remotes: crsh/citr +Config/testthat/edition: 3 Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) RoxygenNote: 7.1.2 +Website: https://github.com/Metropolitan-Council/councilR From 70ab87ae694a6c1ff1e2ab29b78c05058cfe6045 Mon Sep 17 00:00:00 2001 From: Liz Roten Date: Tue, 15 Mar 2022 11:41:28 -0500 Subject: [PATCH 09/14] add @leonx075 as contributor --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 43f2ce9..bcd4238 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,7 +10,8 @@ Authors@R: c( person("Garrick", "Aden-Buie", , "garrick@adenbuie.com", role = "ctb", comment = c(ORCID = "0000-0002-7111-0077")), person("Ellen", "Esch", , "ellen.esch@metc.state.mn.us", role = "ctb", - comment = c(ORCID = "0000-0002-4253-0910")) + comment = c(ORCID = "0000-0002-4253-0910")), + person("Mauricio", "León", , "mauricio.leon@metc.state.mn.us", role = "ctb") ) Description: A collection of commonly used templates, color palettes, functions, and more! From 3d10bf512d012c520ce5241a6a8e542c4726342e Mon Sep 17 00:00:00 2001 From: Liz Roten Date: Tue, 15 Mar 2022 11:43:33 -0500 Subject: [PATCH 10/14] fix copy/paste issues --- R/emissions_db_table_names.R | 2 +- tests/testthat/test-import_from_emissions.R | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/emissions_db_table_names.R b/R/emissions_db_table_names.R index e9b23f6..1994666 100644 --- a/R/emissions_db_table_names.R +++ b/R/emissions_db_table_names.R @@ -13,7 +13,7 @@ #' #' @family datasets #' @examples -#' library(ghg.sp) +#' library(councilR) #' emissions_db_table_names$mod_1 #' emissions_db_table_names$metro_demos # emissions_db_table_names ----- diff --git a/tests/testthat/test-import_from_emissions.R b/tests/testthat/test-import_from_emissions.R index c8d0983..420a56d 100644 --- a/tests/testthat/test-import_from_emissions.R +++ b/tests/testthat/test-import_from_emissions.R @@ -1,7 +1,7 @@ # basic testing testthat::expect_error( - fetch_db_tables( + import_from_emissions( local = FALSE, module = "mod_1" ) @@ -21,7 +21,7 @@ testthat::skip_if(is.null(getOption("councilR.uid"))) testthat::skip_if(is.null(getOption("councilR.pwd"))) -mod_2 <- fetch_db_tables( +mod_2 <- import_from_emissions( module = "mod_2" ) From f02add1ab45fa37ac1a12e98e83035ff315b8800 Mon Sep 17 00:00:00 2001 From: Liz Roten Date: Tue, 15 Mar 2022 11:45:31 -0500 Subject: [PATCH 11/14] add documentation for local paramter --- R/import_from_emissions.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/import_from_emissions.R b/R/import_from_emissions.R index acc8a3d..e3d2baa 100644 --- a/R/import_from_emissions.R +++ b/R/import_from_emissions.R @@ -10,6 +10,7 @@ #' @param module character, which module tables to pull. One of `"mod_1"`, `"mod_2"`, #' `"mod_3"`,` "metro_demos"`, #' `"state_demos"`, `"metro_energy"`, `"state_energy"`, or `"all"` +#' @param local logical, whether to pull from the onsite database or Azure. #' #' @description WARNING: Function error may results in RStudio crash. #' From 68ea3b2af6659d68f002457559806d2cc7bf71b1 Mon Sep 17 00:00:00 2001 From: Liz Roten Date: Tue, 15 Mar 2022 11:45:35 -0500 Subject: [PATCH 12/14] fix typo --- R/colors.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/colors.R b/R/colors.R index fa6b1ea..7bace91 100644 --- a/R/colors.R +++ b/R/colors.R @@ -32,7 +32,7 @@ #' \item{metrostatsMePurple}{Metro Stats medium purple} #' \item{metrostatsLiPurple}{Metro Stats light purple} #' \item{metrostatsPink}{Metro Stats pink} -#' \item{metrostatsTan}{Metro stats tan} +#' \item{metrostatsTan}{Metro Stats tan} #' } #' #' @family aesthetics From e939c809022eaead76ccfd60bf0b56855f108b4f Mon Sep 17 00:00:00 2001 From: Liz Roten Date: Tue, 15 Mar 2022 11:45:59 -0500 Subject: [PATCH 13/14] document and build --- man/colors.Rd | 2 +- man/councilR-package.Rd | 8 ++++++ man/emissions_db_table_names.Rd | 31 +++++++++++++++++++++++ man/import_from_emissions.Rd | 44 +++++++++++++++++++-------------- 4 files changed, 66 insertions(+), 19 deletions(-) create mode 100644 man/emissions_db_table_names.Rd diff --git a/man/colors.Rd b/man/colors.Rd index 9a43726..aca75e6 100644 --- a/man/colors.Rd +++ b/man/colors.Rd @@ -34,7 +34,7 @@ A list of 29 character objects \item{metrostatsMePurple}{Metro Stats medium purple} \item{metrostatsLiPurple}{Metro Stats light purple} \item{metrostatsPink}{Metro Stats pink} -\item{metrostatsTan}{Metro stats tan} +\item{metrostatsTan}{Metro Stats tan} } } \source{ diff --git a/man/councilR-package.Rd b/man/councilR-package.Rd index ecf2876..267260f 100644 --- a/man/councilR-package.Rd +++ b/man/councilR-package.Rd @@ -7,6 +7,13 @@ \title{councilR: Functions and Templates for the Metropolitan Council} \description{ A collection of commonly used templates, color palettes, functions, and more! +} +\seealso{ +Useful links: +\itemize{ + \item Report bugs at \url{https://github.com/Metropolitan-Council/councilR/issues} +} + } \author{ \strong{Maintainer}: Liz Roten \email{liz.roten@metc.state.mn.us} (\href{https://orcid.org/0000-0002-5346-3549}{ORCID}) @@ -16,6 +23,7 @@ Other contributors: \item Metropolitan Council [copyright holder] \item Garrick Aden-Buie \email{garrick@adenbuie.com} (\href{https://orcid.org/0000-0002-7111-0077}{ORCID}) [contributor] \item Ellen Esch \email{ellen.esch@metc.state.mn.us} (\href{https://orcid.org/0000-0002-4253-0910}{ORCID}) [contributor] + \item Mauricio León \email{mauricio.leon@metc.state.mn.us} [contributor] } } diff --git a/man/emissions_db_table_names.Rd b/man/emissions_db_table_names.Rd new file mode 100644 index 0000000..29c9277 --- /dev/null +++ b/man/emissions_db_table_names.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/emissions_db_table_names.R +\docType{data} +\name{emissions_db_table_names} +\alias{emissions_db_table_names} +\title{Emissions database table names} +\format{ +Nested, named list of table names available in the CD_Emissions database +\describe{ +\item{mod_1}{named list of 1 table name} +\item{mod_2}{named list of 3 table names} +\item{mod_3}{named list of 8 table names } +\item{metro_demos}{named list of 7 table names} +\item{state_demos}{named list of 2 table names} +\item{metro_energy}{named list of 9 table names} +\item{state_energy}{named list of 1 table name} +} +} +\usage{ +emissions_db_table_names +} +\description{ +Emissions database table names +} +\examples{ +library(councilR) +emissions_db_table_names$mod_1 +emissions_db_table_names$metro_demos +} +\concept{datasets} +\keyword{datasets} diff --git a/man/import_from_emissions.Rd b/man/import_from_emissions.Rd index 234b7e9..2ca49de 100644 --- a/man/import_from_emissions.Rd +++ b/man/import_from_emissions.Rd @@ -2,12 +2,13 @@ % Please edit documentation in R/import_from_emissions.R \name{import_from_emissions} \alias{import_from_emissions} -\title{Import data table from Emissions Database} +\title{Fetch Greenhouse gas scenario planning data tables} \usage{ import_from_emissions( - uid = councilR.uid, - pwd = councilR.pwd, - table_name = "metro_energy.vw_electricity_residential_ctu", + uid = getOption("councilR.uid"), + pwd = getOption("councilR.pwd"), + module = c("mod_1", "mod_2", "mod_3", "metro_demos", "state_demos", "metro_energy", + "state_energy", "all"), local = TRUE, serv = "dbsqlcl11t.test.local,65414", db = "CD_Emissions" @@ -20,7 +21,11 @@ Default is \code{getOption("councilR.uid")}. For example, \code{"mc\\\\rotenle"} \item{pwd}{character, your network password. Default is \code{getOption("councilR.pwd")}. For example, \code{"my_password"}} -\item{table_name}{character, which table to pull} +\item{module}{character, which module tables to pull. One of \code{"mod_1"}, \code{"mod_2"}, +\code{"mod_3"},\code{ "metro_demos"}, +\code{"state_demos"}, \code{"metro_energy"}, \code{"state_energy"}, or \code{"all"}} + +\item{local}{logical, whether to pull from the onsite database or Azure.} \item{serv}{character, database server. Default is \code{"dbsqlcl11t.test.local,65414"} (the test database).} @@ -28,20 +33,18 @@ Default is \code{"dbsqlcl11t.test.local,65414"} (the test database).} \item{db}{character, database name. Default is \code{"CD_Emissions"}} } \value{ -a table from the CD_Emissions database. +a list of tables from the CD_Emissions database. List length depends +\code{module} parameter. } \description{ -WARNING: Function error may results in RStudio crash. Requires a password for access to the database. +WARNING: Function error may results in RStudio crash. } \note{ -To make connection seamless, add \code{councilR.uid} and \code{councilR.pwd} to your \code{.Rprofile}. Edit your \code{.Rprofile} as such\preformatted{options( - ..., - councilR.uid = "mc\\\\myuid", - councilR.pwd = keyring::key_get("MetC") -) -} - -See more details in \href{https://github.com/Metropolitan-Council/councilR/blob/main/vignettes/Options.Rmd}{\code{{councilR}} documentation}. +See \code{vignette("Options")} to review package options. +You must be set up with the appropriate database drivers to use this function. +\strong{Windows} users need ODBC with Microsoft SQL. Contact IS support for ODBC installation. +\strong{Mac} users need \code{unixodbc} and \code{freetds}. See instructions in +\href{https://github.com/Metropolitan-Council/MetroTransitR}{\code{{MetroTransitR}}} } \examples{ \dontrun{ @@ -53,8 +56,13 @@ options( councilR.pwd = "mypwd" ) -t_electricity_residential_ctu <- import_from_emissions(table_name = "metro_energy.vw_electricity_residential_ctu") -t_eia_energy_consumption_state <- import_from_emissions(table_name = "state_energy.eia_energy_consumption_state") -t_utility_natural_gas_by_ctu <- import_from_emissions(table_name = "metro_energy.vw_utility_natural_gas_by_ctu") +mod_1_tables <- import_from_emissions(module = "mod_1") +mod_2_tables <- import_from_emissions(module = "mod_2") +mod_3_tables <- import_from_emissions(module = "mod_3") + +# or fetch all tables + +all <- import_from_emissions(module = "all") } + } From 14c852449a80deeb7bf7200b30bcf447d0aee43f Mon Sep 17 00:00:00 2001 From: Liz Roten Date: Tue, 15 Mar 2022 11:46:34 -0500 Subject: [PATCH 14/14] change spacing --- R/import_from_emissions.R | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/R/import_from_emissions.R b/R/import_from_emissions.R index e3d2baa..788488c 100644 --- a/R/import_from_emissions.R +++ b/R/import_from_emissions.R @@ -48,16 +48,16 @@ #' @importFrom purrr map flatten #' @importFrom utils osVersion import_from_emissions <- function(uid = getOption("councilR.uid"), - pwd = getOption("councilR.pwd"), - module = c( - "mod_1", "mod_2", "mod_3", - "metro_demos", "state_demos", - "metro_energy", "state_energy", - "all" - ), - local = TRUE, - serv = "dbsqlcl11t.test.local,65414", - db = "CD_Emissions") { + pwd = getOption("councilR.pwd"), + module = c( + "mod_1", "mod_2", "mod_3", + "metro_demos", "state_demos", + "metro_energy", "state_energy", + "all" + ), + local = TRUE, + serv = "dbsqlcl11t.test.local,65414", + db = "CD_Emissions") { # browser() # decide which driver to use based on OS @@ -96,11 +96,11 @@ import_from_emissions <- function(uid = getOption("councilR.uid"), } conn <- DBI::dbConnect(odbc::odbc(), - Driver = drv, - Database = db, - Uid = uid, - Pwd = pwd, - Server = serv + Driver = drv, + Database = db, + Uid = uid, + Pwd = pwd, + Server = serv ) db_sp_tables <- purrr::map(