├── .Rhistory ├── Reporte Automático ├── .Rproj.user │ ├── 19FC512F │ │ ├── sources │ │ │ └── prop │ │ │ │ ├── 424F006 │ │ │ │ ├── 247C10FE │ │ │ │ ├── 49D6051F │ │ │ │ ├── 7D59A7B6 │ │ │ │ ├── 81D42073 │ │ │ │ ├── AAC77AF │ │ │ │ ├── DAB8990B │ │ │ │ ├── E911CD3E │ │ │ │ ├── AF61279E │ │ │ │ ├── 5D055E6C │ │ │ │ └── INDEX │ │ ├── saved_source_markers │ │ ├── pcs │ │ │ ├── source-pane.pper │ │ │ ├── workbench-pane.pper │ │ │ ├── files-pane.pper │ │ │ └── windowlayoutstate.pper │ │ └── rmd-outputs │ ├── D5F44CBE │ │ └── sources │ │ │ └── s-A2649C6C │ │ │ └── lock_file │ └── shared │ │ └── notebooks │ │ ├── patch-chunk-names │ │ ├── D7441DD2-ReportePorRegion │ │ └── 1 │ │ │ └── s │ │ │ ├── c1771xrn4gnsy │ │ │ ├── 000002.csv │ │ │ ├── 000003.metadata │ │ │ └── 000003.png │ │ │ ├── co7p8nc17tzjr │ │ │ ├── 000002.csv │ │ │ ├── 000003.metadata │ │ │ └── 000003.png │ │ │ ├── ctfara1a5p09c │ │ │ ├── 000002.csv │ │ │ ├── 000003.metadata │ │ │ └── 000003.png │ │ │ ├── c1r90upudmcqx │ │ │ ├── 000002.csv │ │ │ └── 000003.png │ │ │ ├── ck4pumevvf3lf │ │ │ └── 000002.csv │ │ │ ├── cyaizffvrfz75 │ │ │ └── 000002.csv │ │ │ ├── c30rv11q2i6y6 │ │ │ └── 000002.csv │ │ │ ├── cmfi2hbdxjls6 │ │ │ └── 000002.csv │ │ │ ├── cucimc2mwdh4d │ │ │ └── 000002.csv │ │ │ ├── ck66wv1vqdtjf │ │ │ └── 000002.csv │ │ │ ├── cfnp9x8n2xdin │ │ │ └── 000002.csv │ │ │ ├── cgjpki5kqy328 │ │ │ └── 000002.csv │ │ │ ├── coqa3jja8q337 │ │ │ └── 000002.csv │ │ │ ├── cxrbtfredys3e │ │ │ └── 000002.csv │ │ │ ├── chunks.json │ │ │ └── cny5rx57wj9oy │ │ │ └── 000002.csv │ │ ├── 5C445995-IntroduccionRMarkdown │ │ └── 1 │ │ │ └── s │ │ │ └── chunks.json │ │ └── paths ├── Mapa │ └── mapa.png ├── calibri.afm.gz ├── FormatoReporte.docx ├── ReportePorRegion.docx ├── Reporte Automático.Rproj ├── Scripts │ ├── CargaDatos.R │ ├── CargarLibrerias.R │ ├── CargaDatos_SQL.R │ ├── Reg.R │ ├── Mapa.R │ ├── ManejoDatos_UF.R │ ├── ManejoDatos_FDC.R │ └── Graficos.R ├── ImprimirReportes.R ├── ReportePorRegion.Rmd ├── ReportePorRegion_SQL.Rmd └── .Rhistory ├── .gitignore ├── UAIJunio_RMarkdown.pdf ├── UAIJunio_RMarkdown.pptx ├── Datos ├── Datos_Sancion.xlsx ├── Datos_Instrumento.xlsx ├── Resumen_UnidadFiscalizable.xlsx └── Detalle_ProcesoSancionUnidadFiscalizable.xlsx ├── Introducción R Markdown ├── IntroduccionRMarkdown.docx ├── .Rhistory └── IntroduccionRMarkdown.Rmd └── README.md /.Rhistory: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/19FC512F/sources/prop/424F006: -------------------------------------------------------------------------------- 1 | { 2 | } -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/D5F44CBE/sources/s-A2649C6C/lock_file: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/patch-chunk-names: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/19FC512F/saved_source_markers: -------------------------------------------------------------------------------- 1 | {"active_set":"","sets":[]} -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/19FC512F/pcs/source-pane.pper: -------------------------------------------------------------------------------- 1 | { 2 | "activeTab" : -1 3 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | Ejemplo Script RStudio/Datos/WDICountry.csv 3 | Ejemplo Script RStudio/Datos/WDIData.csv 4 | -------------------------------------------------------------------------------- /UAIJunio_RMarkdown.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjaguirreh/Reportes-automaticos/HEAD/UAIJunio_RMarkdown.pdf -------------------------------------------------------------------------------- /UAIJunio_RMarkdown.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjaguirreh/Reportes-automaticos/HEAD/UAIJunio_RMarkdown.pptx -------------------------------------------------------------------------------- /Datos/Datos_Sancion.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjaguirreh/Reportes-automaticos/HEAD/Datos/Datos_Sancion.xlsx -------------------------------------------------------------------------------- /Datos/Datos_Instrumento.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjaguirreh/Reportes-automaticos/HEAD/Datos/Datos_Instrumento.xlsx -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/c1771xrn4gnsy/000002.csv: -------------------------------------------------------------------------------- 1 | "0","fdc_reg" 2 | -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/co7p8nc17tzjr/000002.csv: -------------------------------------------------------------------------------- 1 | "0","uf_cat" 2 | -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/ctfara1a5p09c/000002.csv: -------------------------------------------------------------------------------- 1 | "0","uf_reg" 2 | -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/19FC512F/sources/prop/247C10FE: -------------------------------------------------------------------------------- 1 | { 2 | "cursorPosition" : "30,0", 3 | "scrollLine" : "16" 4 | } -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/19FC512F/sources/prop/49D6051F: -------------------------------------------------------------------------------- 1 | { 2 | "cursorPosition" : "37,27", 3 | "scrollLine" : "0" 4 | } -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/19FC512F/sources/prop/7D59A7B6: -------------------------------------------------------------------------------- 1 | { 2 | "cursorPosition" : "0,0", 3 | "scrollLine" : "0" 4 | } -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/19FC512F/sources/prop/81D42073: -------------------------------------------------------------------------------- 1 | { 2 | "cursorPosition" : "10,8", 3 | "scrollLine" : "0" 4 | } -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/19FC512F/sources/prop/AAC77AF: -------------------------------------------------------------------------------- 1 | { 2 | "cursorPosition" : "114,26", 3 | "scrollLine" : "10" 4 | } -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/19FC512F/sources/prop/DAB8990B: -------------------------------------------------------------------------------- 1 | { 2 | "cursorPosition" : "11,56", 3 | "scrollLine" : "0" 4 | } -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/19FC512F/sources/prop/E911CD3E: -------------------------------------------------------------------------------- 1 | { 2 | "cursorPosition" : "12,0", 3 | "scrollLine" : "0" 4 | } -------------------------------------------------------------------------------- /Reporte Automático/Mapa/mapa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjaguirreh/Reportes-automaticos/HEAD/Reporte Automático/Mapa/mapa.png -------------------------------------------------------------------------------- /Reporte Automático/calibri.afm.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjaguirreh/Reportes-automaticos/HEAD/Reporte Automático/calibri.afm.gz -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/19FC512F/sources/prop/AF61279E: -------------------------------------------------------------------------------- 1 | { 2 | "cursorPosition" : "101,163", 3 | "scrollLine" : "62" 4 | } -------------------------------------------------------------------------------- /Datos/Resumen_UnidadFiscalizable.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjaguirreh/Reportes-automaticos/HEAD/Datos/Resumen_UnidadFiscalizable.xlsx -------------------------------------------------------------------------------- /Reporte Automático/FormatoReporte.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjaguirreh/Reportes-automaticos/HEAD/Reporte Automático/FormatoReporte.docx -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/19FC512F/pcs/workbench-pane.pper: -------------------------------------------------------------------------------- 1 | { 2 | "TabSet1" : 0, 3 | "TabSet2" : 4, 4 | "TabZoom" : { 5 | } 6 | } -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/5C445995-IntroduccionRMarkdown/1/s/chunks.json: -------------------------------------------------------------------------------- 1 | {"chunk_definitions":[],"doc_write_time":1591561192} -------------------------------------------------------------------------------- /Reporte Automático/ReportePorRegion.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjaguirreh/Reportes-automaticos/HEAD/Reporte Automático/ReportePorRegion.docx -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/c1r90upudmcqx/000002.csv: -------------------------------------------------------------------------------- 1 | "0","knitr::include_graphics(""Mapa/mapa.png"")" 2 | -------------------------------------------------------------------------------- /Introducción R Markdown/IntroduccionRMarkdown.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjaguirreh/Reportes-automaticos/HEAD/Introducción R Markdown/IntroduccionRMarkdown.docx -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/19FC512F/sources/prop/5D055E6C: -------------------------------------------------------------------------------- 1 | { 2 | "cursorPosition" : "59,172", 3 | "docOutlineVisible" : "0", 4 | "scrollLine" : "54" 5 | } -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/ck4pumevvf3lf/000002.csv: -------------------------------------------------------------------------------- 1 | "0","source(""Scripts/CargaDatos.R"", encoding = ""UTF-8"")" 2 | -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/cyaizffvrfz75/000002.csv: -------------------------------------------------------------------------------- 1 | "0","source(""Scripts/Graficos.R"", encoding = ""UTF-8"")" 2 | -------------------------------------------------------------------------------- /Datos/Detalle_ProcesoSancionUnidadFiscalizable.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjaguirreh/Reportes-automaticos/HEAD/Datos/Detalle_ProcesoSancionUnidadFiscalizable.xlsx -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/c30rv11q2i6y6/000002.csv: -------------------------------------------------------------------------------- 1 | "0","knitr::opts_chunk$set(echo = FALSE, message=FALSE, warning=FALSE, dpi=300)" 2 | -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/c1771xrn4gnsy/000003.metadata: -------------------------------------------------------------------------------- 1 | {"conditions":[],"height":3.200000000000000,"size_behavior":1,"width":7.000000000000000} -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/co7p8nc17tzjr/000003.metadata: -------------------------------------------------------------------------------- 1 | {"conditions":[],"height":2.800000000000000,"size_behavior":1,"width":6.000000000000000} -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/ctfara1a5p09c/000003.metadata: -------------------------------------------------------------------------------- 1 | {"conditions":[],"height":3.000000000000000,"size_behavior":1,"width":6.000000000000000} -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/cmfi2hbdxjls6/000002.csv: -------------------------------------------------------------------------------- 1 | "0","source(""Scripts/Mapa.R"", encoding = ""UTF-8"")" 2 | "2","1 file moved. 0 failed. 3 | " 4 | -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/cucimc2mwdh4d/000002.csv: -------------------------------------------------------------------------------- 1 | "0","source(""Scripts/Mapa.R"", encoding = ""UTF-8"")" 2 | "2","1 file moved. 0 failed. 3 | " 4 | -------------------------------------------------------------------------------- /Introducción R Markdown/.Rhistory: -------------------------------------------------------------------------------- 1 | source('~/GitHub/Reportes-automaticos/Reporte Automático/ImprimirReportes.R', encoding = 'UTF-8', echo=TRUE) 2 | source('~/GitHub/Reportes-automaticos/Reporte Automático/ImprimirReportes.R', encoding = 'UTF-8', echo=TRUE) 3 | -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/19FC512F/pcs/files-pane.pper: -------------------------------------------------------------------------------- 1 | { 2 | "path" : "~/GitHub/Reportes-automaticos/Reporte Automático", 3 | "sortOrder" : [ 4 | { 5 | "ascending" : true, 6 | "columnIndex" : 2 7 | } 8 | ] 9 | } -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/c1771xrn4gnsy/000003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjaguirreh/Reportes-automaticos/HEAD/Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/c1771xrn4gnsy/000003.png -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/c1r90upudmcqx/000003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjaguirreh/Reportes-automaticos/HEAD/Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/c1r90upudmcqx/000003.png -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/ck66wv1vqdtjf/000002.csv: -------------------------------------------------------------------------------- 1 | "0","source(""Scripts/Reg.R"", encoding = ""UTF-8"")" 2 | "0","reg <- as.character(reg3[reg3$reg2 == params$reg, 1]) # esto facilita la impresión masiva de reportes" 3 | -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/co7p8nc17tzjr/000003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjaguirreh/Reportes-automaticos/HEAD/Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/co7p8nc17tzjr/000003.png -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/ctfara1a5p09c/000003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pjaguirreh/Reportes-automaticos/HEAD/Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/ctfara1a5p09c/000003.png -------------------------------------------------------------------------------- /Reporte Automático/Reporte Automático.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: XeLaTeX 14 | -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/19FC512F/pcs/windowlayoutstate.pper: -------------------------------------------------------------------------------- 1 | { 2 | "left" : { 3 | "panelheight" : 937, 4 | "splitterpos" : 328, 5 | "topwindowstate" : "HIDE", 6 | "windowheight" : 975 7 | }, 8 | "right" : { 9 | "panelheight" : 937, 10 | "splitterpos" : 548, 11 | "topwindowstate" : "NORMAL", 12 | "windowheight" : 975 13 | } 14 | } -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/19FC512F/rmd-outputs: -------------------------------------------------------------------------------- 1 | ~/GitHub/Reportes-automaticos/Reporte Automático/ReportePorRegion.docx 2 | ~/GitHub/Reportes-automaticos/Reporte Automático/ReportePorRegion.docx 3 | ~/GitHub/Reportes-automaticos/Reporte Automático/ReportePorRegion.docx 4 | ~/GitHub/Reportes-automaticos/Reporte Automático/ReportePorRegion.docx 5 | ~/GitHub/Reportes-automaticos/Reporte Automático/ReportePorRegion.docx 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/cfnp9x8n2xdin/000002.csv: -------------------------------------------------------------------------------- 1 | "0","source(""Scripts/ManejoDatos_UF.R"", encoding = ""UTF-8"")" 2 | "2","`summarise()` ungrouping output (override with `.groups` argument) 3 | " 4 | "2","`summarise()` ungrouping output (override with `.groups` argument) 5 | " 6 | "2","`summarise()` ungrouping output (override with `.groups` argument) 7 | " 8 | "2","Selecting by RCAs 9 | " 10 | -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/cgjpki5kqy328/000002.csv: -------------------------------------------------------------------------------- 1 | "0","source(""Scripts/ManejoDatos_UF.R"", encoding = ""UTF-8"")" 2 | "2","`summarise()` ungrouping output (override with `.groups` argument) 3 | " 4 | "2","`summarise()` ungrouping output (override with `.groups` argument) 5 | " 6 | "2","`summarise()` ungrouping output (override with `.groups` argument) 7 | " 8 | "2","Selecting by RCAs 9 | " 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Reportes automáticos 2 | ================ 3 | 4 | Consiste en un tutorial de como usar *R Markdown* a través de un caso práctico implementado en la [Superintendencia del Medio Ambiente](https://portal.sma.gob.cl/). **Los datos utilizados no son reales**. 5 | 6 | Presentación hecha para: 7 | - [Laboratorio de Gobierno](https://noticias.uai.cl/como-utilizar-la-programacion-r/). 8 | - [UAI Campus Viña del Mar](https://noticias.uai.cl/evento/charla-demostrativa-automatizando-reportes-con-r/). 9 | - [Presentación on-line para el Laboratorio de Gobierno](https://www.youtube.com/watch?v=QfeTzUF_8Nk) -------------------------------------------------------------------------------- /Reporte Automático/Scripts/CargaDatos.R: -------------------------------------------------------------------------------- 1 | # Cargar datos desde (4) planillas 2 | 3 | Resumen_UnidadFiscalizable <- read_excel("../Datos/Resumen_UnidadFiscalizable.xlsx") 4 | 5 | Datos_Instrumento <- read_excel("../Datos/Datos_Instrumento.xlsx") 6 | 7 | Detalle_ProcesoSancionUnidadFiscalizable <- read_excel("../Datos/Detalle_ProcesoSancionUnidadFiscalizable.xlsx") 8 | 9 | Datos_Sancion <- read_excel("../Datos/Datos_Sancion.xlsx") 10 | 11 | Datos_Sancion <- Datos_Sancion %>% 12 | mutate(RegionSelect = case_when( 13 | Region == reg ~ reg, 14 | TRUE ~ "Resto de las Regiones")) 15 | -------------------------------------------------------------------------------- /Reporte Automático/ImprimirReportes.R: -------------------------------------------------------------------------------- 1 | # Valores que se usarán como "parámetros" (variables) del reporte 2 | regiones <- c("Tarapacá", "Antofagasta", "Atacama", "Coquimbo", "O'Higgins", 3 | "Valparaíso", "Maule", "Biobío", "Araucanía", "Lagos", "Aysén", 4 | "Magallanes", "Metropolitana", "Ríos", "Arica", "Ñuble") 5 | 6 | # Definir función para generación de reportes 7 | for (i in regiones){ 8 | rmarkdown::render("ReportePorRegion.Rmd", 9 | params = list(reg = i), 10 | output_file = paste0("Reportes/Reporte_", i, "_", format(Sys.Date(), "%d-%m-%Y")) 11 | ) 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/coqa3jja8q337/000002.csv: -------------------------------------------------------------------------------- 1 | "0","source(""Scripts/ManejoDatos_FDC.R"", encoding = ""UTF-8"")" 2 | "2","`summarise()` ungrouping output (override with `.groups` argument) 3 | " 4 | "2","`summarise()` regrouping output by 'AnoExpediente' (override with `.groups` argument) 5 | " 6 | "2","`summarise()` ungrouping output (override with `.groups` argument) 7 | " 8 | "2","`summarise()` regrouping output by 'CategoriaEconomica' (override with `.groups` argument) 9 | " 10 | "2","`summarise()` ungrouping output (override with `.groups` argument) 11 | " 12 | "2","`summarise()` ungrouping output (override with `.groups` argument) 13 | " 14 | -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/cxrbtfredys3e/000002.csv: -------------------------------------------------------------------------------- 1 | "0","source(""Scripts/ManejoDatos_FDC.R"", encoding = ""UTF-8"")" 2 | "2","`summarise()` ungrouping output (override with `.groups` argument) 3 | " 4 | "2","`summarise()` regrouping output by 'AnoExpediente' (override with `.groups` argument) 5 | " 6 | "2","`summarise()` ungrouping output (override with `.groups` argument) 7 | " 8 | "2","`summarise()` regrouping output by 'CategoriaEconomica' (override with `.groups` argument) 9 | " 10 | "2","`summarise()` ungrouping output (override with `.groups` argument) 11 | " 12 | "2","`summarise()` ungrouping output (override with `.groups` argument) 13 | " 14 | -------------------------------------------------------------------------------- /Reporte Automático/Scripts/CargarLibrerias.R: -------------------------------------------------------------------------------- 1 | # Paquetes a usar 2 | lista_paquetes <- c("dplyr", "ggplot2", "lubridate", "tidyr", "kableExtra", "flextable", "filesstrings", 3 | "purrr", "readr", "extrafont", "stringr", "ggmap", "readxl", "leaflet", "mapview", "purrr") 4 | 5 | # Revisar si paquetes están instalados. Si lo están, cargará los paquetes. Si no lo están, instalará y luego cargará los paquetes. 6 | nuevos_paquetes <- lista_paquetes[!(lista_paquetes %in% installed.packages()[,"Package"])] 7 | lapply(nuevos_paquetes, install.packages); lapply(lista_paquetes, require, character.only = TRUE) 8 | 9 | rm(lista_paquetes, nuevos_paquetes) 10 | #font_import() 11 | loadfonts(device = "win") 12 | 13 | -------------------------------------------------------------------------------- /Reporte Automático/Scripts/CargaDatos_SQL.R: -------------------------------------------------------------------------------- 1 | library(DBI) 2 | library(odbc) 3 | 4 | # Conectar a SQL 5 | con <- dbConnect(odbc::odbc(), 6 | encoding = "windows-1252", 7 | .connection_string = "Driver={SQL Server};Server=XXXXXX;Database=XXXXX;trusted_connection=yes") 8 | 9 | # Cargar datos desde (4) planillas en SQL 10 | 11 | Resumen_UnidadFiscalizable <- dbGetQuery(con, "SELECT * FROM master..Resumen_UnidadFiscalizable") 12 | 13 | Datos_Instrumento <- dbGetQuery(con, "SELECT * FROM master..Datos_Instrumento") 14 | 15 | Detalle_ProcesoSancionUnidadFiscalizable <- dbGetQuery(con, "SELECT * FROM master..Detalle_ProcesoSAncionUnidadFiscalizable") 16 | 17 | Datos_Sancion <- dbGetQuery(con, "SELECT * FROM master..Datos_Sancion") 18 | 19 | Datos_Sancion <- Datos_Sancion %>% 20 | mutate(RegionSelect = case_when( 21 | Region == reg ~ reg, 22 | TRUE ~ "Resto de las Regiones")) 23 | -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/19FC512F/sources/prop/INDEX: -------------------------------------------------------------------------------- 1 | ~%2FGitHub%2FReportes-automaticos%2FIntroducci%C3%B3n%20R%20Markdown%2FIntroduccionRMarkdown.Rmd="AF61279E" 2 | ~%2FGitHub%2FReportes-automaticos%2FReporte%20Autom%C3%A1tico%2FImprimirReportes.R="E911CD3E" 3 | ~%2FGitHub%2FReportes-automaticos%2FReporte%20Autom%C3%A1tico%2FReportePorRegion.Rmd="5D055E6C" 4 | ~%2FGitHub%2FReportes-automaticos%2FReporte%20Autom%C3%A1tico%2FScripts%2FCargaDatos.R="81D42073" 5 | ~%2FGitHub%2FReportes-automaticos%2FReporte%20Autom%C3%A1tico%2FScripts%2FCargarLibrerias.R="7D59A7B6" 6 | ~%2FGitHub%2FReportes-automaticos%2FReporte%20Autom%C3%A1tico%2FScripts%2FGraficos.R="AAC77AF" 7 | ~%2FGitHub%2FReportes-automaticos%2FReporte%20Autom%C3%A1tico%2FScripts%2FManejoDatos_FDC.R="247C10FE" 8 | ~%2FGitHub%2FReportes-automaticos%2FReporte%20Autom%C3%A1tico%2FScripts%2FManejoDatos_UF.R="49D6051F" 9 | ~%2FGitHub%2FReportes-automaticos%2FReporte%20Autom%C3%A1tico%2FScripts%2FMapa.R="424F006" 10 | ~%2FGitHub%2FReportes-automaticos%2FReporte%20Autom%C3%A1tico%2FScripts%2FReg.R="DAB8990B" 11 | -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/paths: -------------------------------------------------------------------------------- 1 | C:/Users/pjagu/OneDrive/Documents/GitHub/Reportes-automaticos/Introducción R Markdown/IntroduccionRMarkdown.Rmd="5C445995" 2 | C:/Users/pjagu/OneDrive/Documents/GitHub/Reportes-automaticos/Reporte Automático/ImprimirReportes.R="170EFD2" 3 | C:/Users/pjagu/OneDrive/Documents/GitHub/Reportes-automaticos/Reporte Automático/ReportePorRegion.Rmd="D7441DD2" 4 | C:/Users/pjagu/OneDrive/Documents/GitHub/Reportes-automaticos/Reporte Automático/Scripts/CargaDatos.R="F46D3E2B" 5 | C:/Users/pjagu/OneDrive/Documents/GitHub/Reportes-automaticos/Reporte Automático/Scripts/CargarLibrerias.R="6B944384" 6 | C:/Users/pjagu/OneDrive/Documents/GitHub/Reportes-automaticos/Reporte Automático/Scripts/Graficos.R="ABD130D9" 7 | C:/Users/pjagu/OneDrive/Documents/GitHub/Reportes-automaticos/Reporte Automático/Scripts/ManejoDatos_FDC.R="9418665" 8 | C:/Users/pjagu/OneDrive/Documents/GitHub/Reportes-automaticos/Reporte Automático/Scripts/ManejoDatos_UF.R="C69CEC15" 9 | C:/Users/pjagu/OneDrive/Documents/GitHub/Reportes-automaticos/Reporte Automático/Scripts/Mapa.R="A26098A3" 10 | C:/Users/pjagu/OneDrive/Documents/GitHub/Reportes-automaticos/Reporte Automático/Scripts/Reg.R="34562533" 11 | -------------------------------------------------------------------------------- /Reporte Automático/Scripts/Reg.R: -------------------------------------------------------------------------------- 1 | reg1 <- c("Región de Tarapacá" 2 | , "Región de Antofagasta" 3 | , "Región de Atacama" 4 | , "Región de Coquimbo" 5 | , "Región del Libertador General Bernardo O'Higgins" 6 | , "Región de Valparaíso" 7 | , "Región del Maule" 8 | , "Región del Biobío" 9 | , "Región de la Araucanía" 10 | , "Región de los Lagos" 11 | , "Región de Aysén del General Carlos Ibañez del Campo" 12 | , "Región de Magallanes y la Antártica Chilena" 13 | , "Región Metropolitana" 14 | , "Región de Los Ríos" 15 | , "Región de Arica y Parinacota" 16 | , "Región de Ñuble") 17 | 18 | reg2 <- c("Tarapacá" 19 | , "Antofagasta" 20 | , "Atacama" 21 | , "Coquimbo" 22 | , "O'Higgins" 23 | , "Valparaíso" 24 | , "Maule" 25 | , "Biobío" 26 | , "Araucanía" 27 | , "Lagos" 28 | , "Aysén" 29 | , "Magallanes" 30 | , "Metropolitana" 31 | , "Ríos" 32 | , "Arica" 33 | , "Ñuble") 34 | 35 | 36 | reg3 <- as.data.frame(cbind(reg1,reg2)) -------------------------------------------------------------------------------- /Reporte Automático/Scripts/Mapa.R: -------------------------------------------------------------------------------- 1 | centroides <- tribble( 2 | ~Region, ~latitud, ~longitud, 3 | "Región de Arica y Parinacota", -18.496932, -69.62854, 4 | "Región de Tarapacá", -20.215794, -69.393066, 5 | "Región de Antofagasta", -23.53599, -69.119139, 6 | "Región de Atacama", -27.395285, -69.910141, 7 | "Región de Coquimbo", -30.619033, -70.860692, 8 | "Región de Valparaíso", -32.782424, -70.959617, 9 | "Región Metropolitana", -33.604344, -70.627063, 10 | "Región del Libertador General Bernardo O'Higgins", -34.435366, -71.046566, 11 | "Región del Maule", -35.62133, -71.445649, 12 | "Región de Ñuble", -36.645411, -71.974643, 13 | "Región del Biobío", -37.500562, -72.392417, 14 | "Región de la Araucanía", -38.649155, -72.27425, 15 | "Región de Los Ríos", -40.004982, -72.570862, 16 | "Región de los Lagos", -42.04281, -72.89418, 17 | "Región de Aysén del General Carlos Ibáñez del Campo", -46.416524, -73.257083, 18 | "Región de Magallanes y la Antártica Chilena", -52.488319, -71.873603 19 | ) 20 | 21 | coord_uf <- Resumen_UnidadFiscalizable %>% 22 | select("RegionNombre", "Latitud", "Longitud") %>% 23 | filter(RegionNombre == reg, !is.na(Latitud), !is.na(Longitud)) 24 | 25 | if (reg == "Región de Aysén del General Carlos Ibáñez del Campo"){ 26 | long <- unique(coord_uf$Longitud_reg) 27 | ltd <- unique(coord_uf$Latitud_reg) 28 | } else { 29 | long <- filter(centroides, Region == reg)$longitud 30 | ltd <- filter(centroides, Region == reg)$latitud 31 | } 32 | 33 | if (reg %in% c("Región de Antofagasta", "Región de Atacama", "Región de Coquimbo", "Región de los Lagos", 34 | "Región de Aysén del General Carlos Ibáñez del Campo", "Región de Magallanes y la Antártica Chilena")){ 35 | z <- 7 36 | } else { 37 | z <- 8 38 | } 39 | 40 | m <- leaflet(coord_uf) %>% 41 | setView(lng = long, lat = ltd, zoom = z) %>% 42 | addProviderTiles(providers$CartoDB.Positron) %>% 43 | addCircleMarkers(~Longitud, ~Latitud, color = "red", weight = 1, radius = 3) 44 | 45 | mapshot(m, file = "~/mapa.png") 46 | 47 | file.move("~/mapa.png", "Mapa/", overwrite = TRUE) 48 | -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/chunks.json: -------------------------------------------------------------------------------- 1 | {"chunk_definitions":[{"chunk_id":"c30rv11q2i6y6","chunk_label":"opciones de cada chunk de código","document_id":"BDA6E508","expansion_state":0,"options":{"echo":false,"engine":"r","label":"opciones de cada chunk de código"},"row":11,"row_count":1,"visible":true},{"chunk_id":"cny5rx57wj9oy","chunk_label":"Librerías/Pquetes","document_id":"1EBD9E55","expansion_state":0,"options":{"engine":"r","include":false,"label":"Librerías/Pquetes"},"row":16,"row_count":1,"visible":true},{"chunk_id":"ck66wv1vqdtjf","chunk_label":"Definir Regiones","document_id":"1EBD9E55","expansion_state":0,"options":{"engine":"r","include":false,"label":"Definir Regiones"},"row":21,"row_count":1,"visible":true},{"chunk_id":"ck4pumevvf3lf","chunk_label":"Cargar Datos","document_id":"1EBD9E55","expansion_state":0,"options":{"engine":"r","label":"Cargar Datos"},"row":30,"row_count":1,"visible":true},{"chunk_id":"cgjpki5kqy328","chunk_label":"Datos: UF","document_id":"BDA6E508","expansion_state":0,"options":{"engine":"r","label":"Datos: UF"},"row":34,"row_count":1,"visible":true},{"chunk_id":"cxrbtfredys3e","chunk_label":"Datos: FDC","document_id":"BDA6E508","expansion_state":0,"options":{"engine":"r","label":"Datos: FDC"},"row":38,"row_count":1,"visible":true},{"chunk_id":"cyaizffvrfz75","chunk_label":"Gráficos","document_id":"1EBD9E55","expansion_state":0,"options":{"engine":"r","label":"Gráficos"},"row":42,"row_count":1,"visible":true},{"chunk_id":"cmfi2hbdxjls6","chunk_label":"Mapa","document_id":"BDA6E508","expansion_state":0,"options":{"engine":"r","label":"Mapa"},"row":46,"row_count":1,"visible":true},{"chunk_id":"crxf6ug1im1ng","chunk_label":"Gráfico: top 5 UF RCA","document_id":"1EBD9E55","expansion_state":0,"options":{"engine":"r","fig.align":"center","fig.height":3,"fig.width":6,"label":"Gráfico: top 5 UF RCA"},"row":87,"row_count":1,"visible":true},{"chunk_id":"c1771xrn4gnsy","chunk_label":"Gráfico: FDC region","document_id":"BDA6E508","expansion_state":0,"options":{"engine":"r","fig.align":"center","fig.height":3.200000000000000,"fig.width":7,"label":"Gráfico: FDC region"},"row":102,"row_count":1,"visible":true}],"doc_write_time":1591735644} -------------------------------------------------------------------------------- /Reporte Automático/Scripts/ManejoDatos_UF.R: -------------------------------------------------------------------------------- 1 | # Datos: UF por región 2 | UF_reg <- Resumen_UnidadFiscalizable %>% filter(RegionNombre == reg) 3 | 4 | resumen_reg <- Resumen_UnidadFiscalizable %>% 5 | group_by("Región" = RegionNombre) %>% 6 | summarise(UFs = n()) %>% 7 | arrange(desc(UFs)) %>% 8 | ungroup() %>% 9 | mutate(Porcentaje = round(UFs/sum(UFs)*100,1), 10 | Destacar = case_when(`Región` == reg ~ "Si", 11 | is.na(`Región`) ~ "Si2", 12 | TRUE ~ "No"), 13 | orden_reg = case_when( 14 | `Región` == "Región de Arica y Parinacota" ~ 17, 15 | `Región` == "Región de Tarapacá" ~ 16, 16 | `Región` == "Región de Antofagasta" ~ 15, 17 | `Región` == "Región de Atacama" ~ 14, 18 | `Región` == "Región de Coquimbo" ~ 13, 19 | `Región` == "Región Metropolitana" ~ 12, 20 | `Región` == "Región de Valparaíso" ~ 11, 21 | `Región` == "Región del Libertador General Bernardo O'Higgins" ~ 10, 22 | `Región` == "Región del Maule" ~ 9, 23 | `Región` == "Región de Ñuble" ~ 8, 24 | `Región` == "Región del Biobío" ~ 7, 25 | `Región` == "Región de la Araucanía" ~ 6, 26 | `Región` == "Región de Los Ríos" ~ 5, 27 | `Región` == "Región de los Lagos" ~ 4, 28 | `Región` == "Región de Aysén del General Carlos Ibañez del Campo" ~ 3, 29 | `Región` == "Región de Magallanes y la Antártica Chilena" ~ 2, 30 | is.na(`Región`) ~ 1 31 | )) 32 | 33 | Porcentaje_uf_reg <- filter(resumen_reg, `Región` == reg)[[3]] 34 | 35 | # Datos: UF por categoría 36 | 37 | resumen_cate <- Resumen_UnidadFiscalizable %>% 38 | filter(RegionNombre == reg) %>% 39 | group_by("Categoría Económica" = CategoriaEconomicaNombre) %>% 40 | summarise(UFs = n()) %>% 41 | arrange(desc(UFs)) %>% 42 | ungroup() %>% 43 | mutate(Porcentaje = round(UFs/sum(UFs)*100,1), 44 | Destacar = case_when(is.na(`Categoría Económica`) ~ "Si", 45 | TRUE ~ "No")) 46 | 47 | # Datos: Top 5 Cat por RCA 48 | 49 | top_RCA <- Datos_Instrumento %>% 50 | filter(SiglaInstrumento == "RCA", #Instrumento de inter?s 51 | NombreRegion == reg #Filtro región 52 | #Existen RCAs "interregionales" que en "NombreRegionPoryecto" especifican región (acá se consideran) 53 | | (NombreRegion == "Interregional" & NombreRegionProyecto == reg)) %>% # | signfica "o" 54 | group_by(CategoriaEconomicaNombre) %>% 55 | summarise(RCAs = n()) %>% 56 | ungroup() %>% 57 | rename("Categoría Económica" = CategoriaEconomicaNombre) %>% 58 | arrange(desc(RCAs)) %>% 59 | top_n(5) 60 | -------------------------------------------------------------------------------- /Reporte Automático/Scripts/ManejoDatos_FDC.R: -------------------------------------------------------------------------------- 1 | # Datos: FdC por región 2 | 3 | FDC_reg_porcentaje <- Datos_Sancion %>% 4 | distinct(ProcesoSancionId, Region, AnoInicio, AnoExpediente) %>% 5 | group_by(Region) %>% 6 | summarise(FDC = n()) %>% 7 | replace_na(list(Region = "Sin Región")) %>% 8 | arrange(desc(FDC)) %>% 9 | mutate(Porcentaje = round(FDC/sum(FDC)*100,1), 10 | Destacar = case_when(Region == reg ~ "Si", 11 | TRUE ~ "No"), 12 | orden_reg = case_when( 13 | Region == "Región de Arica y Parinacota" ~ 16, 14 | Region == "Región de Tarapacá" ~ 15, 15 | Region == "Región de Antofagasta" ~ 14, 16 | Region == "Región de Atacama" ~ 13, 17 | Region == "Región de Coquimbo" ~ 12, 18 | Region == "Región Metropolitana" ~ 11, 19 | Region == "Región de Valparaíso" ~ 10, 20 | Region == "Región del Libertador General Bernardo O'Higgins" ~ 9, 21 | Region == "Región del Maule" ~ 8, 22 | Region == "Región de Ñuble" ~ 7, 23 | Region == "Región del Biobío" ~ 6, 24 | Region == "Región de la Araucanía" ~ 5, 25 | Region == "Región de Los Ríos" ~ 4, 26 | Region == "Región de los Lagos" ~ 3, 27 | Region == "Región de Aysén del General Carlos Ibañez del Campo" ~ 2, 28 | Region == "Región de Magallanes y la Antártica Chilena" ~ 1 29 | ), 30 | rank = 1:n()) 31 | 32 | # Datos: FdC por año 33 | 34 | FDC_año <- Datos_Sancion %>% 35 | distinct(ProcesoSancionId, RegionSelect, AnoInicio, AnoExpediente) %>% 36 | group_by(AnoExpediente, RegionSelect) %>% 37 | summarise(FDC = (n())) %>% 38 | arrange(AnoExpediente) 39 | 40 | # Datos: FdC categoría 41 | 42 | Comparar <- FDC_año %>% 43 | ungroup() %>% group_by(RegionSelect) %>% 44 | summarise(sum(FDC)) 45 | 46 | FDC_cate <- Datos_Sancion %>% 47 | distinct(ProcesoSancionId, CategoriaEconomica, AnoInicio, AnoExpediente, RegionSelect) %>% 48 | group_by(CategoriaEconomica, RegionSelect) %>% 49 | summarise(FDC = n()) %>% 50 | ungroup() %>% 51 | group_by(RegionSelect) %>% 52 | mutate(Porcentaje = round(FDC/sum(FDC)*100,1), 53 | Destacar = case_when(is.na(CategoriaEconomica) ~ "Si", 54 | TRUE ~ "No")) %>% 55 | filter(RegionSelect == reg) 56 | 57 | MAX_cate <- FDC_cate %>% filter(RegionSelect == reg) %>% 58 | arrange(desc(FDC)) 59 | 60 | # Datos: FDC origen 61 | 62 | FDC_origen <- Datos_Sancion %>% 63 | filter(Region == reg) %>% 64 | distinct(ProcesoSancionId, ProcesoSancionTipoNombre) %>% 65 | group_by(ProcesoSancionTipoNombre) %>% 66 | summarise(FDC = n()) %>% 67 | mutate(Porcentaje = round(FDC/sum(FDC)*100,0)) %>% 68 | arrange(desc(FDC)) 69 | 70 | # Datos: FDC estado 71 | 72 | FDC_estado <- Datos_Sancion %>% 73 | distinct(ProcesoSancionId, Region, AnoInicio, AnoExpediente, ProcesoSancionEstadoNombre) %>% 74 | filter(Region == reg) %>% 75 | mutate(Estado = case_when( 76 | ProcesoSancionEstadoNombre %in% c("Terminado - PDC", "PDC Ejecutado", "PDC en Análisis", "PDC en Ejecución") ~ "En PDC", 77 | ProcesoSancionEstadoNombre %in% c("Terminado - Absolución", "Terminado - Archivado", "Terminado - Sanción") ~ "Terminado", 78 | TRUE ~ "En proceso" 79 | )) %>% 80 | group_by(Estado) %>% 81 | summarise(FDC = n()) %>% 82 | mutate(Porcentaje = round(FDC/sum(FDC)*100,1)) 83 | 84 | FDC_estado_detalle <- Datos_Sancion %>% 85 | distinct(ProcesoSancionId, Region, AnoInicio, AnoExpediente, ProcesoSancionEstadoNombre) %>% 86 | filter(Region == reg) 87 | 88 | -------------------------------------------------------------------------------- /Reporte Automático/ReportePorRegion.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | author: Pablo Aguirre Hörmann 3 | output: #word_document 4 | word_document: 5 | reference_docx: FormatoReporte.docx 6 | params: 7 | reg: "Magallanes" 8 | --- 9 | 10 | ```{r opciones de cada chunk de código, echo=FALSE} 11 | knitr::opts_chunk$set(echo = FALSE, message=FALSE, warning=FALSE, dpi=300) 12 | ``` 13 | 14 | ```{r Librerías/Pquetes, include = FALSE} 15 | source("Scripts/CargarLibrerias.R", encoding = "UTF-8") 16 | windowsFonts("Arial" = windowsFont("Calibri")) 17 | ``` 18 | 19 | ```{r Definir Regiones, include=FALSE} 20 | source("Scripts/Reg.R", encoding = "UTF-8") 21 | reg <- as.character(reg3[reg3$reg2 == params$reg, 1]) # esto facilita la impresión masiva de reportes 22 | ``` 23 | 24 | --- 25 | title: Minuta `r reg` 26 | date: `r format(Sys.Date(), "%d/%m/%Y")` 27 | --- 28 | 29 | ```{r Cargar Datos} 30 | source("Scripts/CargaDatos.R", encoding = "UTF-8") 31 | ``` 32 | 33 | ```{r Datos: UF} 34 | source("Scripts/ManejoDatos_UF.R", encoding = "UTF-8") 35 | ``` 36 | 37 | ```{r Datos: FDC} 38 | source("Scripts/ManejoDatos_FDC.R", encoding = "UTF-8") 39 | ``` 40 | 41 | ```{r Gráficos} 42 | source("Scripts/Graficos.R", encoding = "UTF-8") 43 | ``` 44 | 45 | ```{r Mapa} 46 | source("Scripts/Mapa.R", encoding = "UTF-8") 47 | ``` 48 | 49 | 50 | # 1. Sobre la información presentada [^1] 51 | 52 | ###### A continuación, se presenta un ejemplo de minuta con diferentes indicadores asociados a la **`r reg`**. Los datos son simulados y no deben ser considerados en ningún caso como información oficial de la SMA. Este reporte fue generado el **`r format(Sys.Date(), "%d/%m/%Y")`**. 53 | 54 | [^1]: **UF**: Unidad Fiscalizable / **RCA**: Resolución de Calificación Ambiental / **IA**: Inspección Ambiental / **PPDA**: Plan de Prevensión y Descontaminación Ambiental / **RSMA**: Resolución de normas e instrucciones de carácter de la Superintendencia de Medio ambiente / **PC/PDC**: Programa de Cumplimiento / **NC**: Norma de Contaminación / **LEY**: Ley Ambiental / **REG**: Reglamento / **NE**: Norma de Emisión / **MP**: Medida Provisional / **FDC**: Formulación de Cargos / **MM**: Millones 55 | 56 | 57 | # 2. Unidades Fiscalizables 58 | 59 | - **`r prettyNum(nrow(UF_reg), big.mark = ".", decimal.mark = ",")`** de las **`r prettyNum(nrow(Resumen_UnidadFiscalizable), big.mark = ".", decimal.mark = ",")`** Unidades Fiscalizables (UF) a nivel nacional corresponden a la **`r reg`** (`r paste0(Porcentaje_uf_reg, "%")`). 60 | - Estas se concentran mayoritariamente en la categoría **`r resumen_cate[1,1]`** (`r resumen_cate[1,2]` UFs), seguida por la **`r resumen_cate[2,1]`** (`r resumen_cate[2,2]` UFs) 61 | 62 | ## 2.1 Localización UFs en la `r reg` 63 | 64 | ```{r Mapa UFs, out.width="400px", fig.align="center"} 65 | knitr::include_graphics("Mapa/mapa.png") 66 | ``` 67 | 68 | ## 2.2 Distribución de UFs a nivel nacional 69 | 70 | ```{r Gráfico: UFs por región, fig.width=6, fig.height=3, fig.align="center"} 71 | uf_reg 72 | ``` 73 | 74 | ## 2.3 UFs de la `r reg` por sector 75 | 76 | ```{r Gráfico: UFs por categoría económica, fig.width=6, fig.height=2.8, fig.align="center"} 77 | uf_cat 78 | ``` 79 | 80 | ## 2.4 Las 5 Categorías Económicas de `r reg` con más RCA 81 | 82 | ```{r Gráfico: top 5 UF RCA, fig.width=6, fig.height=3, fig.align="center"} 83 | top_RCA %>% 84 | flextable() %>% 85 | width(j = c(1, 2), width = c(1.8, 1)) %>% 86 | font(fontname = "Calibri", part = "all") %>% 87 | fontsize(size = 10, part = "all") 88 | ``` 89 | 90 | # 3. Formulaciones de cargo 91 | 92 | ## 6.1 Formulaciones de cargo (FDC) 93 | 94 | * La `r reg` ocupa el lugar `r filter(FDC_reg_porcentaje, Region == reg)$rank` respecto al resto de las regiones en número de FdC. 95 | * De **`r prettyNum(Comparar[1,2] + Comparar[2,2], big.mark = ".", decimal.mark = ",")`** FdC, **`r Comparar[1,2]`** (**`r paste0(prettyNum(round(Comparar[1,2]/(Comparar[1,2] + Comparar[2,2])*100,1), big.mark = ".", decimal.mark = ","),"%")`**) han sido en la **`r reg`**. 96 | * Dentro de la **`r reg`**, `r prettyNum(round(FDC_origen$FDC[FDC_origen$ProcesoSancionTipoNombre == "Denuncia"]/sum(FDC_origen$FDC)*100,1), big.mark = ".", decimal.mark = ",")`% de las FdC fueron iniciadas a partir de **denuncias**. 97 | * **`r MAX_cate$CategoriaEconomica[1]`** es el sector que concentra el mayor número de FdC en la `r reg` (`r MAX_cate$FDC[1]`) seguida por **`r MAX_cate$CategoriaEconomica[2]`** (`r MAX_cate$FDC[2]`). 98 | 99 | ### FDC por región 100 | 101 | ```{r Gráfico: FDC region, fig.width=7, fig.height=3.2, fig.align="center"} 102 | fdc_reg 103 | ``` 104 | 105 | ### FDC asociadas a la `r reg` por año 106 | 107 | ```{r Gráfico: FDC Año, fig.width=4.8, fig.height=2, fig.align="center"} 108 | fdc_anio 109 | ``` 110 | 111 | ### Distribución de FDC asociadas a la `r reg` por sector 112 | 113 | ```{r Gráfico FDC por categoria, fig.width=6, fig.height=3, fig.align="center"} 114 | fdc_cat 115 | ``` 116 | 117 | ### FDC asociadas a la `r reg` por origen 118 | 119 | ```{r Gráfico FDC Origen, fig.width=3.3, fig.height=2.2, fig.align="center"} 120 | fdc_origen 121 | ``` 122 | 123 | ### FDC asociadas a la `r reg` por estado 124 | 125 | ```{r Gráfico FDC Estado, fig.width=3.3, fig.height=2.2, fig.align="center"} 126 | fdc_estado 127 | ``` -------------------------------------------------------------------------------- /Reporte Automático/ReportePorRegion_SQL.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | author: Pablo Aguirre Hörmann 3 | output: #word_document 4 | word_document: 5 | reference_docx: FormatoReporte.docx 6 | params: 7 | reg: "Magallanes" 8 | --- 9 | 10 | ```{r opciones de cada chunk de código, echo=FALSE} 11 | knitr::opts_chunk$set(echo = FALSE, message=FALSE, warning=FALSE, dpi=300) 12 | ``` 13 | 14 | ```{r Librerías/Pquetes, include = FALSE} 15 | source("Scripts/CargarLibrerias.R", encoding = "UTF-8") 16 | windowsFonts("Arial" = windowsFont("Calibri")) 17 | ``` 18 | 19 | ```{r Definir Regiones, include=FALSE} 20 | source("Scripts/Reg.R", encoding = "UTF-8") 21 | reg <- as.character(reg3[reg3$reg2 == params$reg, 1]) # esto facilita la impresión masiva de reportes 22 | ``` 23 | 24 | --- 25 | title: Minuta `r reg` 26 | date: `r format(Sys.Date(), "%d/%m/%Y")` 27 | --- 28 | 29 | ```{r Cargar Datos} 30 | source("Scripts/CargaDatos_SQL.R", encoding = "UTF-8") 31 | ``` 32 | 33 | ```{r Datos: UF} 34 | source("Scripts/ManejoDatos_UF.R", encoding = "UTF-8") 35 | ``` 36 | 37 | ```{r Datos: FDC} 38 | source("Scripts/ManejoDatos_FDC.R", encoding = "UTF-8") 39 | ``` 40 | 41 | ```{r Gráficos} 42 | source("Scripts/Graficos.R", encoding = "UTF-8") 43 | ``` 44 | 45 | ```{r Mapa} 46 | source("Scripts/Mapa.R", encoding = "UTF-8") 47 | ``` 48 | 49 | 50 | # 1. Sobre la información presentada [^1] 51 | 52 | ###### A continuación, se presenta un ejemplo de minuta con diferentes indicadores asociados a la **`r reg`**. Los datos son simulados y no deben ser considerados en ningún caso como información oficial de la SMA. Este reporte fue generado el **`r format(Sys.Date(), "%d/%m/%Y")`**. 53 | 54 | [^1]: **UF**: Unidad Fiscalizable / **RCA**: Resolución de Calificación Ambiental / **IA**: Inspección Ambiental / **PPDA**: Plan de Prevensión y Descontaminación Ambiental / **RSMA**: Resolución de normas e instrucciones de carácter de la Superintendencia de Medio ambiente / **PC/PDC**: Programa de Cumplimiento / **NC**: Norma de Contaminación / **LEY**: Ley Ambiental / **REG**: Reglamento / **NE**: Norma de Emisión / **MP**: Medida Provisional / **FDC**: Formulación de Cargos / **MM**: Millones 55 | 56 | 57 | # 2. Unidades Fiscalizables 58 | 59 | - **`r prettyNum(nrow(UF_reg), big.mark = ".", decimal.mark = ",")`** de las **`r prettyNum(nrow(Resumen_UnidadFiscalizable), big.mark = ".", decimal.mark = ",")`** Unidades Fiscalizables (UF) a nivel nacional corresponden a la **`r reg`** (`r paste0(Porcentaje_uf_reg, "%")`). 60 | - Estas se concentran mayoritariamente en la categoría **`r resumen_cate[1,1]`** (`r resumen_cate[1,2]` UFs), seguida por la **`r resumen_cate[2,1]`** (`r resumen_cate[2,2]` UFs) 61 | 62 | ## 2.1 Localización UFs en la `r reg` 63 | 64 | ```{r Mapa UFs, out.width="400px", fig.align="center"} 65 | knitr::include_graphics("Mapa/mapa.png") 66 | ``` 67 | 68 | ## 2.2 Distribución de UFs a nivel nacional 69 | 70 | ```{r Gráfico: UFs por región, fig.width=6, fig.height=3, fig.align="center"} 71 | uf_reg 72 | ``` 73 | 74 | ## 2.3 UFs de la `r reg` por sector 75 | 76 | ```{r Gráfico: UFs por categoría económica, fig.width=6, fig.height=2.8, fig.align="center"} 77 | uf_cat 78 | ``` 79 | 80 | ## 2.4 Las 5 Categorías Económicas de `r reg` con más RCA 81 | 82 | ```{r Gráfico: top 5 UF RCA, fig.width=6, fig.height=3, fig.align="center"} 83 | top_RCA %>% 84 | flextable() %>% 85 | width(j = c(1, 2), width = c(1.8, 1)) %>% 86 | font(fontname = "Calibri", part = "all") %>% 87 | fontsize(size = 10, part = "all") 88 | ``` 89 | 90 | # 3. Formulaciones de cargo 91 | 92 | ## 6.1 Formulaciones de cargo (FDC) 93 | 94 | * La `r reg` ocupa el lugar `r filter(FDC_reg_porcentaje, Region == reg)$rank` respecto al resto de las regiones en número de FdC. 95 | * De **`r prettyNum(Comparar[1,2] + Comparar[2,2], big.mark = ".", decimal.mark = ",")`** FdC, **`r Comparar[1,2]`** (**`r paste0(prettyNum(round(Comparar[1,2]/(Comparar[1,2] + Comparar[2,2])*100,1), big.mark = ".", decimal.mark = ","),"%")`**) han sido en la **`r reg`**. 96 | * Dentro de la **`r reg`**, `r prettyNum(round(FDC_origen$FDC[FDC_origen$ProcesoSancionTipoNombre == "Denuncia"]/sum(FDC_origen$FDC)*100,1), big.mark = ".", decimal.mark = ",")`% de las FdC fueron iniciadas a partir de **denuncias**. 97 | * **`r MAX_cate$CategoriaEconomica[1]`** es el sector que concentra el mayor número de FdC en la `r reg` (`r MAX_cate$FDC[1]`) seguida por **`r MAX_cate$CategoriaEconomica[2]`** (`r MAX_cate$FDC[2]`). 98 | 99 | ### FDC por región 100 | 101 | ```{r Gráfico: FDC region, fig.width=7, fig.height=3.2, fig.align="center"} 102 | fdc_reg 103 | ``` 104 | 105 | ### FDC asociadas a la `r reg` por año 106 | 107 | ```{r Gráfico: FDC Año, fig.width=4.8, fig.height=2, fig.align="center"} 108 | fdc_anio 109 | ``` 110 | 111 | ### Distribución de FDC asociadas a la `r reg` por sector 112 | 113 | ```{r Gráfico FDC por categoria, fig.width=6, fig.height=3, fig.align="center"} 114 | fdc_cat 115 | ``` 116 | 117 | ### FDC asociadas a la `r reg` por origen 118 | 119 | ```{r Gráfico FDC Origen, fig.width=3.3, fig.height=2.2, fig.align="center"} 120 | fdc_origen 121 | ``` 122 | 123 | ### FDC asociadas a la `r reg` por estado 124 | 125 | ```{r Gráfico FDC Estado, fig.width=3.3, fig.height=2.2, fig.align="center"} 126 | fdc_estado 127 | ``` -------------------------------------------------------------------------------- /Reporte Automático/Scripts/Graficos.R: -------------------------------------------------------------------------------- 1 | # UFs por región 2 | 3 | uf_reg <- resumen_reg %>% 4 | ggplot(aes(reorder(`Región`, orden_reg), Porcentaje, label = paste0(prettyNum(Porcentaje, big.mark = ".", decimal.mark = ","),"%", " (", prettyNum(UFs, big.mark = ".", decimal.mark = ","),")"), fill = Destacar)) + 5 | geom_col() + 6 | ylim(0, max(resumen_cate$Porcentaje)*1.22) + 7 | coord_flip() + 8 | geom_text(hjust = -0.22, size = 3) + 9 | scale_fill_manual(values = c("Si" = "#E87474", "No" = "light blue", "Si2" = "light gray")) + 10 | theme(panel.background = element_rect(fill = NA), 11 | legend.position = "none", 12 | plot.title = element_text(hjust = 0.5), 13 | axis.title.x = element_blank(), 14 | axis.title.y = element_blank(), 15 | axis.ticks.x = element_blank(), 16 | axis.ticks.y = element_blank(), 17 | axis.text.x = element_blank(), 18 | text = element_text(family = "Calibri") 19 | ) 20 | 21 | # UFs por categoría económica 22 | 23 | uf_cat <- resumen_cate %>% 24 | ggplot(aes(reorder(`Categoría Económica`, Porcentaje), Porcentaje, label = paste0(prettyNum(Porcentaje, big.mark = ".", decimal.mark = ","),"%", " (", prettyNum(UFs, big.mark = ".", decimal.mark = ","), ")"), fill = Destacar)) + 25 | geom_col() + 26 | ylim(0, max(resumen_cate$Porcentaje)*1.2) + 27 | coord_flip() + 28 | geom_text(hjust = -0.05, size = 3) + 29 | scale_fill_manual(values = c("Si" = "light gray", "No" = "light blue")) + 30 | theme(panel.background = element_rect(fill = NA), 31 | legend.position = "none", 32 | plot.title = element_text(hjust = 0.5), 33 | axis.title.x = element_blank(), 34 | axis.title.y = element_blank(), 35 | axis.ticks.x = element_blank(), 36 | axis.ticks.y = element_blank(), 37 | axis.text.x = element_blank(), 38 | text = element_text(family = "Calibri") 39 | ) 40 | 41 | # FDC region 42 | 43 | fdc_reg <- FDC_reg_porcentaje %>% 44 | ggplot(aes(reorder(Region, orden_reg), Porcentaje, label = paste0(prettyNum(Porcentaje, big.mark = ".", decimal.mark = ","), "%", " (", prettyNum(FDC, big.mark = ".", decimal.mark = ","), ")"), fill = Destacar)) + 45 | geom_col() + 46 | ylim(0, max(FDC_reg_porcentaje$Porcentaje)*1.25) + 47 | coord_flip() + 48 | geom_text(hjust = -0.22, size = 3) + 49 | scale_fill_manual(values = c("Si" = "#E87474", "No" = "light blue", "Si2" = "light gray")) + 50 | theme(panel.background = element_rect(fill = NA), 51 | legend.position = "none", 52 | plot.title = element_text(hjust = 0.5), 53 | axis.title.x = element_blank(), 54 | axis.title.y = element_blank(), 55 | axis.ticks.x = element_blank(), 56 | axis.ticks.y = element_blank(), 57 | axis.text.x = element_blank(), 58 | text = element_text(family = "Calibri") 59 | ) 60 | 61 | # FDC Año 62 | 63 | fdc_anio <- FDC_año %>% 64 | filter(RegionSelect == reg) %>% 65 | ggplot(aes(AnoExpediente, FDC, label = FDC)) + 66 | geom_line(color = "light blue", size = 2) + 67 | geom_label(color = "#E87474") + 68 | ylim(min(FDC_año[FDC_año$RegionSelect == reg,]$FDC)-2, max(FDC_año[FDC_año$RegionSelect == reg,]$FDC)*1.05) + 69 | scale_x_continuous(breaks = c(2012:2019)) + 70 | labs(y = "FDC") + 71 | theme(panel.background = element_rect(fill = NA), 72 | legend.position = "top", 73 | legend.title = element_blank(), 74 | legend.key = element_rect(size = 1), 75 | legend.key.size = unit(0.5, 'lines'), 76 | plot.title = element_text(hjust = 0.5), 77 | axis.title.x = element_blank(), 78 | axis.title.y = element_blank(), 79 | axis.ticks.x = element_blank(), 80 | axis.ticks.y = element_blank(), 81 | axis.text.y = element_blank(), 82 | text = element_text(family = "Calibri") 83 | ) 84 | 85 | # FDC categoria 86 | 87 | fdc_cat <- FDC_cate %>% 88 | ggplot(aes(reorder(CategoriaEconomica, Porcentaje), Porcentaje, label = paste0(prettyNum(Porcentaje, big.mark = ".", decimal.mark = ","), "%", " (", prettyNum(FDC, big.mark = ".", decimal.mark = ","), ")"), fill = Destacar)) + 89 | geom_col() + 90 | ylim(0, max(FDC_cate$Porcentaje)*1.2) + 91 | coord_flip() + 92 | geom_text(hjust = -0.22, size = 3) + 93 | scale_fill_manual(values = c("Si" = "light gray", "No" = "light blue")) + 94 | theme(panel.background = element_rect(fill = NA), 95 | legend.position = "none", 96 | plot.title = element_text(hjust = 0.5), 97 | axis.title.x = element_blank(), 98 | axis.title.y = element_blank(), 99 | axis.ticks.x = element_blank(), 100 | axis.ticks.y = element_blank(), 101 | axis.text.x = element_blank(), 102 | text = element_text(family = "Calibri") 103 | ) 104 | 105 | # FDC Origen 106 | 107 | fdc_origen <- FDC_origen %>% 108 | ggplot(aes(ProcesoSancionTipoNombre, Porcentaje, label = paste0(Porcentaje, "%", " (", FDC, ")"))) + 109 | geom_col(fill = "light blue", width = 0.6) + 110 | ylim(0, max(FDC_origen$Porcentaje)*1.05) + 111 | geom_text(vjust = -0.5, size = 3) + 112 | labs(y = "Porcentaje (%)") + 113 | theme(panel.background = element_rect(fill = NA), 114 | legend.position = "top", 115 | legend.title = element_blank(), 116 | legend.key = element_rect(size = 1), 117 | legend.key.size = unit(0.5, 'lines'), 118 | plot.title = element_text(hjust = 0.5), 119 | axis.title.x = element_blank(), 120 | axis.title.y = element_blank(), 121 | axis.ticks.x = element_blank(), 122 | axis.ticks.y = element_blank(), 123 | axis.text.y = element_blank(), 124 | axis.text.x = element_text(margin = margin(t = -5)), 125 | text = element_text(family = "Calibri") 126 | ) 127 | 128 | # FDC Estado 129 | 130 | fdc_estado <- FDC_estado %>% 131 | ggplot(aes(Estado, Porcentaje, label = paste0(Porcentaje, "%", " (", FDC, ")"))) + 132 | geom_col(fill = "light blue", width = 0.6) + 133 | ylim(0, max(FDC_estado$Porcentaje)*1.05) + 134 | geom_text(vjust = -0.5, size = 3) + 135 | labs(y = "Porcentaje (%)") + 136 | theme(panel.background = element_rect(fill = NA), 137 | legend.position = "top", 138 | legend.title = element_blank(), 139 | legend.key = element_rect(size = 1), 140 | legend.key.size = unit(0.5, 'lines'), 141 | plot.title = element_text(hjust = 0.5), 142 | axis.title.x = element_blank(), 143 | axis.title.y = element_blank(), 144 | axis.ticks.x = element_blank(), 145 | axis.ticks.y = element_blank(), 146 | axis.text.y = element_blank(), 147 | axis.text.x = element_text(margin = margin(t = -5)), 148 | text = element_text(family = "Calibri") 149 | ) -------------------------------------------------------------------------------- /Introducción R Markdown/IntroduccionRMarkdown.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Introducción a R Markdown" 3 | author: "Pablo Aguirre Hörmann" 4 | date: "6/7/2020" 5 | output: 6 | html_document: 7 | df_print: paged 8 | code_folding: hide 9 | word_document: default 10 | --- 11 | 12 | ```{r, include=FALSE} 13 | knitr::opts_chunk$set(echo = TRUE) 14 | ``` 15 | 16 | 17 | # R Markdown 18 | 19 | Este es un archivo de tipo *R Markdown* (`.Rmd`), en este tipo de archivos podemos de manera simple intercalar texto con código. 20 | 21 | El código se define en los "pedazos de código" (*code chunks*): 22 | 23 | ```{r} 24 | # Una suma por ejemplo 25 | 2 + 2 26 | ``` 27 | 28 | ```{r, fig.align='center', fig.width=5, fig.height=4} 29 | # o un gráfico simple 30 | x <- 1:10 31 | y <- rnorm(10) 32 | plot(x, y) 33 | ``` 34 | 35 | Y estos "pedazos de código" tienen distintas opciones que por ejemplos nos permiten solo motrar el resultado y no el código que lo genera (`echo = FALSE`): 36 | 37 | ```{r, echo = FALSE, fig.align='center', fig.width=5, fig.height=4} 38 | hist(y) 39 | ``` 40 | 41 | # Formato de texto 42 | 43 | Así como hay formas de manipular el código que trabajemos existe también una gran variedad de opciones para dar formato al texto que queramos incluir en un documento: 44 | 45 | - *cursiva* 46 | - **negrita** 47 | - __*cursiva y negrita*__ 48 | - ~~tachado~~ 49 | - [link](https://gobierno.uai.cl/centro-investigacion/goblab-uai/) 50 | - `Objetos de código` 51 | - entre otras.. 52 | 53 | También podemos definir distintos niveles de jerarquía respecto a títulos y subtítulos 54 | 55 | 56 | # Título 1 (`# Título 1`) 57 | ## Título 2 (`## Título 2`) 58 | ### Título 3 (`### Título 3`) 59 | #### Título 4 (`#### Título 4`) 60 | ##### Título 5 (`##### Título 5`) 61 | ###### Título 6 (`###### Título 6`) 62 | 63 | Por otro lado, este tipo de archivo también nos facilita escribir formulas/operaciones/objetos matemáticos (con sintáxis $\LaTeX$) tanto en linea con el texto ($\sum_{i=1}^n X_i$) como en su propio párrafo: 64 | 65 | $$\int_0^{2\pi} \sin x~dx$$ 66 | 67 | $$\mathbf{X} = \left[\begin{array} 68 | {rrr} 69 | 1 & 2 & 3 \\ 70 | 4 & 5 & 6 \\ 71 | 7 & 8 & 9 72 | \end{array}\right] $$ 73 | 74 | Incluso podemos agregar imágenes directamente a nuestros documentos: 75 | ![](https://goblab.uai.cl/wp-content/uploads/2019/12/Logo-GobLab-UAI.png) 76 | 77 | # Código en línea 78 | 79 | Una de las principales caractéristicas que nos facilitará la creación de reportes automatizados es que no solo podemos escribir código en los "pedazos de código" (*code chunks*) sino que también podemos escribir **código en línea con el texto**. 80 | 81 | ```{r} 82 | resultado <- 2 + 2 83 | rel <- round(cor(x,y), 2) 84 | ``` 85 | 86 | La suma del cálculo hecho arriba es igual a **`r resultado`** y la correlación entre `x` e `y` es **`r rel`**. 87 | 88 | __*Para más información sobre como trabajar con documentos en R Markdown ver [la hoja de referencia](https://www.rstudio.com/wp-content/uploads/2015/03/rmarkdown-spanish.pdf) y el libro [R Markdown: The Definitive Guide](https://bookdown.org/yihui/rmarkdown/)*__ 89 | 90 | # Cargar datos a R 91 | 92 | `R` puede cargar datos de manera bastante sencilla desde distintos origenes, en esta demostación trabajaremos con planillas. Por ejemplo, cargaremos información desde un archivo `csv`: 93 | 94 | ```{r, message=FALSE} 95 | library(readxl) # librería con funciones de carga de datos optimizadas 96 | Resumen_UnidadFiscalizable <- read_excel("../Datos/Resumen_UnidadFiscalizable.xlsx") 97 | head(Resumen_UnidadFiscalizable) 98 | ``` 99 | 100 | *Muchas de las funcionalidades que ocupes en `R` tendrán que ser cargadas desde librerías/paquetes. Estas se deben instalar una sola vez (`install.packages("NombreLibreria")`) y cargadas en cada nueva sesión de `R` (`library(NombreLibreria)`)* 101 | 102 | Ahora bien, en muchos casos tendrán que interactuar con datos obtenidos desde motores de base de datos (por ejemplo *MS SQL Server*). En ese caso, para cargar datos, primero se debe generar una conexión con la base de datos para luego "llamar" las tablas que querramos ir usando. 103 | 104 | ```{r, include = FALSE} 105 | library(DBI) 106 | library(odbc) 107 | library(RSQLite) 108 | con <- dbConnect(RSQLite::SQLite(), dbname = ":memory:") 109 | dplyr::copy_to(con, Resumen_UnidadFiscalizable, "Resumen_UnidadFiscalizable", 110 | temporary = FALSE 111 | ) 112 | ``` 113 | 114 | Una conexión a un motor de base de datos se ve más o menos así: 115 | 116 | ```{r, eval = FALSE} 117 | # Cargamos librerías para la conexión con motores de bases de datos 118 | library(DBI) 119 | library(odbc) 120 | 121 | con <- dbConnect(odbc(), 122 | Driver = "SQL Server", 123 | Server = "ServidorX", 124 | Database = "BBDD", 125 | Trusted_Connection = "True", 126 | Port = 1433) 127 | ``` 128 | 129 | Y dos formas de cargar estos datos en `R` son: 130 | 131 | ```{r, collapse=TRUE} 132 | head(dbReadTable(con, "Resumen_UnidadFiscalizable")) 133 | head(dplyr::tbl(con, "Resumen_UnidadFiscalizable")) 134 | ``` 135 | 136 | __*Para más información sobre el uso de bases de datos con R ver el [siguiente link](https://db.rstudio.com/)*__ 137 | 138 | # Manejo de datos 139 | 140 | Ahora bien, cuando queramos realizar reportes tendrémos que probablemente manipular la información que tenemos. Esto dependerá de cada caso y habrán distintas formas de hacerlo. Por ejemplo, a continuación tomaremos los datos recién cargados y: 141 | 142 | 1. Seleccionaremos solo algunas de las variables/columnas para trabajar (función `select()`) 143 | 2. Filtraremos (seleccionaremos filas) los datos para eliminar valores nulos respecto a dos variables (función `filter()`) 144 | 3. Agruparemos las observaciones respecto a Región y Sector económico para luego calcular en número de UFs para cada grupo (funciónes `group_by()` y `summarise()`) 145 | 4. Los pasos anteriores generarán una "planilla" de varias filas y tres columnas que luego será modificada a un formato "más cuadrado" (función `spread()`) 146 | 147 | *Todos estos pasos son distintas operaciones que serán unidas a través de un operador llamado "la pipa" (`%>%`) que permite escribir código con acciones de izquierda a derecha.* 148 | 149 | ```{r, message=FALSE, warning=FALSE} 150 | library(dplyr) # librería de manejo de datos (seleccionar, filtrar, agrupar, etc) 151 | library(tidyr) # librería para modificación de "forma" de datos ("pivot", "unpivot") 152 | 153 | # Generamos un nuevo data set "Resumen_UnidadFiscalizable_cuadro" luego de hacer toda la manipulación 154 | 155 | Resumen_UnidadFiscalizable_cuadro <- 156 | # datos originales 157 | Resumen_UnidadFiscalizable %>% 158 | # seleccionamos cuatro variables/columnas 159 | select(UnidadFiscalizableId, RegionNombre, CategoriaEconomicaNombre) %>% 160 | # dejamos solo aquellas observaciones/filas que no tienen valores nulos para RegionNombre ni CategoriaEconomicaNombre 161 | filter(!is.na(RegionNombre) & !is.na(CategoriaEconomicaNombre)) %>% 162 | # Agrupamos las observaciones/filas respecto a las variables RegionNombre y CategoriaEconomicaNombre 163 | group_by(RegionNombre, CategoriaEconomicaNombre) %>% 164 | # Calculamos el número de filas/observaciones para cada uno de los grupos 165 | summarise("Número de UFs" = n()) %>% 166 | # Modificamos la forma de los datos (a "más cuadrado") 167 | spread(CategoriaEconomicaNombre, `Número de UFs`) 168 | 169 | Resumen_UnidadFiscalizable_cuadro 170 | ``` 171 | 172 | # Visualización 173 | 174 | De forma similar podemos también 175 | 176 | ```{r, fig.align='center'} 177 | Resumen_UnidadFiscalizable_reg <- 178 | # datos originales 179 | Resumen_UnidadFiscalizable %>% 180 | # seleccionamos cuatro variables/columnas 181 | select(UnidadFiscalizableId, RegionNombre, CategoriaEconomicaNombre) %>% 182 | # dejamos solo aquellas observaciones/filas que no tienen valores nulos para RegionNombre ni CategoriaEconomicaNombre 183 | filter(!is.na(RegionNombre) & !is.na(CategoriaEconomicaNombre)) %>% 184 | # Agrupamos las observaciones/filas respecto a las variables RegionNombre y CategoriaEconomicaNombre 185 | group_by(RegionNombre, CategoriaEconomicaNombre) %>% 186 | # Calculamos el número de filas/observaciones para cada uno de los grupos 187 | summarise("Número de UFs" = n()) 188 | 189 | library(ggplot2) 190 | 191 | Resumen_UnidadFiscalizable_reg %>% 192 | ggplot(aes(RegionNombre, `Número de UFs`)) + 193 | geom_col() + 194 | coord_flip() + 195 | xlab("") + 196 | ylab("") 197 | ``` 198 | 199 | __*En estos ejemplos usamos principalmente librerías del denominado `tidyverse` que es un conjunto de librerías especializadas en *data science*. Para más información pueden revisar el [siguiente link](https://www.tidyverse.org/)*__ -------------------------------------------------------------------------------- /Reporte Automático/.Rproj.user/shared/notebooks/D7441DD2-ReportePorRegion/1/s/cny5rx57wj9oy/000002.csv: -------------------------------------------------------------------------------- 1 | "0","source(""Scripts/CargarLibrerias.R"", encoding = ""UTF-8"")" 2 | "2","Agency FB already registered with windowsFonts(). 3 | " 4 | "2","Algerian already registered with windowsFonts(). 5 | " 6 | "2","Anonymous already registered with windowsFonts(). 7 | " 8 | "2","Arial Black already registered with windowsFonts(). 9 | " 10 | "2","Arial already registered with windowsFonts(). 11 | " 12 | "2","Arial Narrow already registered with windowsFonts(). 13 | " 14 | "2","Arial Rounded MT Bold already registered with windowsFonts(). 15 | " 16 | "2","Bahnschrift already registered with windowsFonts(). 17 | " 18 | "2","Baskerville Old Face already registered with windowsFonts(). 19 | " 20 | "2","Bauhaus 93 already registered with windowsFonts(). 21 | " 22 | "2","Bell MT already registered with windowsFonts(). 23 | " 24 | "2","Berlin Sans FB already registered with windowsFonts(). 25 | " 26 | "2","Berlin Sans FB Demi already registered with windowsFonts(). 27 | " 28 | "2","Bernard MT Condensed already registered with windowsFonts(). 29 | " 30 | "2","Blackadder ITC already registered with windowsFonts(). 31 | " 32 | "2","Bodoni MT already registered with windowsFonts(). 33 | " 34 | "2","Bodoni MT Black already registered with windowsFonts(). 35 | " 36 | "2","Bodoni MT Condensed already registered with windowsFonts(). 37 | " 38 | "2","Bodoni MT Poster Compressed already registered with windowsFonts(). 39 | " 40 | "2","Book Antiqua already registered with windowsFonts(). 41 | " 42 | "2","Bookman Old Style already registered with windowsFonts(). 43 | " 44 | "2","Bookshelf Symbol 7 already registered with windowsFonts(). 45 | " 46 | "2","Bradley Hand ITC already registered with windowsFonts(). 47 | " 48 | "2","Britannic Bold already registered with windowsFonts(). 49 | " 50 | "2","Broadway already registered with windowsFonts(). 51 | " 52 | "2","Brush Script MT already registered with windowsFonts(). 53 | " 54 | "2","Calibri already registered with windowsFonts(). 55 | " 56 | "2","Calibri Light already registered with windowsFonts(). 57 | " 58 | "2","Californian FB already registered with windowsFonts(). 59 | " 60 | "2","Calisto MT already registered with windowsFonts(). 61 | " 62 | "2","Cambria already registered with windowsFonts(). 63 | " 64 | "2","Candara already registered with windowsFonts(). 65 | " 66 | "2","Candara Light already registered with windowsFonts(). 67 | " 68 | "2","Castellar already registered with windowsFonts(). 69 | " 70 | "2","Centaur already registered with windowsFonts(). 71 | " 72 | "2","Century already registered with windowsFonts(). 73 | " 74 | "2","Century Gothic already registered with windowsFonts(). 75 | " 76 | "2","Century Schoolbook already registered with windowsFonts(). 77 | " 78 | "2","Chiller already registered with windowsFonts(). 79 | " 80 | "2","Colonna MT already registered with windowsFonts(). 81 | " 82 | "2","Comic Sans MS already registered with windowsFonts(). 83 | " 84 | "2","Consolas already registered with windowsFonts(). 85 | " 86 | "2","Constantia already registered with windowsFonts(). 87 | " 88 | "2","Cooper Black already registered with windowsFonts(). 89 | " 90 | "2","Copperplate Gothic Bold already registered with windowsFonts(). 91 | " 92 | "2","Copperplate Gothic Light already registered with windowsFonts(). 93 | " 94 | "2","Corbel already registered with windowsFonts(). 95 | " 96 | "2","Corbel Light already registered with windowsFonts(). 97 | " 98 | "2","Courier New already registered with windowsFonts(). 99 | " 100 | "2","Curlz MT already registered with windowsFonts(). 101 | " 102 | "2","Dubai already registered with windowsFonts(). 103 | " 104 | "2","Dubai Light already registered with windowsFonts(). 105 | " 106 | "2","Dubai Medium already registered with windowsFonts(). 107 | " 108 | "2","Ebrima already registered with windowsFonts(). 109 | " 110 | "2","Edwardian Script ITC already registered with windowsFonts(). 111 | " 112 | "2","Elephant already registered with windowsFonts(). 113 | " 114 | "2","Engravers MT already registered with windowsFonts(). 115 | " 116 | "2","Eras Bold ITC already registered with windowsFonts(). 117 | " 118 | "2","Eras Demi ITC already registered with windowsFonts(). 119 | " 120 | "2","Eras Light ITC already registered with windowsFonts(). 121 | " 122 | "2","Eras Medium ITC already registered with windowsFonts(). 123 | " 124 | "2","Felix Titling already registered with windowsFonts(). 125 | " 126 | "2","Footlight MT Light already registered with windowsFonts(). 127 | " 128 | "2","Forte already registered with windowsFonts(). 129 | " 130 | "2","Franklin Gothic Book already registered with windowsFonts(). 131 | " 132 | "2","Franklin Gothic Demi already registered with windowsFonts(). 133 | " 134 | "2","Franklin Gothic Demi Cond already registered with windowsFonts(). 135 | " 136 | "2","Franklin Gothic Heavy already registered with windowsFonts(). 137 | " 138 | "2","Franklin Gothic Medium already registered with windowsFonts(). 139 | " 140 | "2","Franklin Gothic Medium Cond already registered with windowsFonts(). 141 | " 142 | "2","Freestyle Script already registered with windowsFonts(). 143 | " 144 | "2","French Script MT already registered with windowsFonts(). 145 | " 146 | "2","Gabriola already registered with windowsFonts(). 147 | " 148 | "2","Gadugi already registered with windowsFonts(). 149 | " 150 | "2","Garamond already registered with windowsFonts(). 151 | " 152 | "2","Georgia already registered with windowsFonts(). 153 | " 154 | "2","Gigi already registered with windowsFonts(). 155 | " 156 | "2","Gill Sans Ultra Bold already registered with windowsFonts(). 157 | " 158 | "2","Gill Sans Ultra Bold Condensed already registered with windowsFonts(). 159 | " 160 | "2","Gill Sans MT already registered with windowsFonts(). 161 | " 162 | "2","Gill Sans MT Condensed already registered with windowsFonts(). 163 | " 164 | "2","Gill Sans MT Ext Condensed Bold already registered with windowsFonts(). 165 | " 166 | "2","Gloucester MT Extra Condensed already registered with windowsFonts(). 167 | " 168 | "2","Goudy Old Style already registered with windowsFonts(). 169 | " 170 | "2","Goudy Stout already registered with windowsFonts(). 171 | " 172 | "2","Haettenschweiler already registered with windowsFonts(). 173 | " 174 | "2","Harlow Solid Italic already registered with windowsFonts(). 175 | " 176 | "2","Harrington already registered with windowsFonts(). 177 | " 178 | "2","High Tower Text already registered with windowsFonts(). 179 | " 180 | "2","HoloLens MDL2 Assets already registered with windowsFonts(). 181 | " 182 | "2","Impact already registered with windowsFonts(). 183 | " 184 | "2","Imprint MT Shadow already registered with windowsFonts(). 185 | " 186 | "2","Informal Roman already registered with windowsFonts(). 187 | " 188 | "2","Ink Free already registered with windowsFonts(). 189 | " 190 | "2","Javanese Text already registered with windowsFonts(). 191 | " 192 | "2","Jokerman already registered with windowsFonts(). 193 | " 194 | "2","Juice ITC already registered with windowsFonts(). 195 | " 196 | "2","Kristen ITC already registered with windowsFonts(). 197 | " 198 | "2","Kunstler Script already registered with windowsFonts(). 199 | " 200 | "2","Wide Latin already registered with windowsFonts(). 201 | " 202 | "2","Leelawadee already registered with windowsFonts(). 203 | " 204 | "2","Leelawadee UI already registered with windowsFonts(). 205 | " 206 | "2","Leelawadee UI Semilight already registered with windowsFonts(). 207 | " 208 | "2","Lucida Bright already registered with windowsFonts(). 209 | " 210 | "2","Lucida Calligraphy already registered with windowsFonts(). 211 | " 212 | "2","Lucida Console already registered with windowsFonts(). 213 | " 214 | "2","Lucida Fax already registered with windowsFonts(). 215 | " 216 | "2","Lucida Handwriting already registered with windowsFonts(). 217 | " 218 | "2","Lucida Sans already registered with windowsFonts(). 219 | " 220 | "2","Lucida Sans Typewriter already registered with windowsFonts(). 221 | " 222 | "2","Lucida Sans Unicode already registered with windowsFonts(). 223 | " 224 | "2","Magneto already registered with windowsFonts(). 225 | " 226 | "2","Maiandra GD already registered with windowsFonts(). 227 | " 228 | "2","Malgun Gothic already registered with windowsFonts(). 229 | " 230 | "2","Malgun Gothic Semilight already registered with windowsFonts(). 231 | " 232 | "2","Marlett already registered with windowsFonts(). 233 | " 234 | "2","Matura MT Script Capitals already registered with windowsFonts(). 235 | " 236 | "2","Microsoft Himalaya already registered with windowsFonts(). 237 | " 238 | "2","Microsoft Yi Baiti already registered with windowsFonts(). 239 | " 240 | "2","Microsoft New Tai Lue already registered with windowsFonts(). 241 | " 242 | "2","Microsoft PhagsPa already registered with windowsFonts(). 243 | " 244 | "2","Microsoft Sans Serif already registered with windowsFonts(). 245 | " 246 | "2","Microsoft Tai Le already registered with windowsFonts(). 247 | " 248 | "2","Microsoft Uighur already registered with windowsFonts(). 249 | " 250 | "2","Mistral already registered with windowsFonts(). 251 | " 252 | "2","Modern No. 20 already registered with windowsFonts(). 253 | " 254 | "2","Mongolian Baiti already registered with windowsFonts(). 255 | " 256 | "2","Monotype Corsiva already registered with windowsFonts(). 257 | " 258 | "2","MS Outlook already registered with windowsFonts(). 259 | " 260 | "2","MS Reference Sans Serif already registered with windowsFonts(). 261 | " 262 | "2","MS Reference Specialty already registered with windowsFonts(). 263 | " 264 | "2","MV Boli already registered with windowsFonts(). 265 | " 266 | "2","Myanmar Text already registered with windowsFonts(). 267 | " 268 | "2","Niagara Engraved already registered with windowsFonts(). 269 | " 270 | "2","Niagara Solid already registered with windowsFonts(). 271 | " 272 | "2","Nirmala UI already registered with windowsFonts(). 273 | " 274 | "2","Nirmala UI Semilight already registered with windowsFonts(). 275 | " 276 | "2","OCR A Extended already registered with windowsFonts(). 277 | " 278 | "2","Old English Text MT already registered with windowsFonts(). 279 | " 280 | "2","Onyx already registered with windowsFonts(). 281 | " 282 | "2","Palace Script MT already registered with windowsFonts(). 283 | " 284 | "2","Palatino Linotype already registered with windowsFonts(). 285 | " 286 | "2","Papyrus already registered with windowsFonts(). 287 | " 288 | "2","Parchment already registered with windowsFonts(). 289 | " 290 | "2","Perpetua already registered with windowsFonts(). 291 | " 292 | "2","Perpetua Titling MT already registered with windowsFonts(). 293 | " 294 | "2","Playbill already registered with windowsFonts(). 295 | " 296 | "2","Poor Richard already registered with windowsFonts(). 297 | " 298 | "2","Pristina already registered with windowsFonts(). 299 | " 300 | "2","Rage Italic already registered with windowsFonts(). 301 | " 302 | "2","Ravie already registered with windowsFonts(). 303 | " 304 | "2","Rockwell already registered with windowsFonts(). 305 | " 306 | "2","Rockwell Condensed already registered with windowsFonts(). 307 | " 308 | "2","Rockwell Extra Bold already registered with windowsFonts(). 309 | " 310 | "2","Script MT Bold already registered with windowsFonts(). 311 | " 312 | "2","Segoe MDL2 Assets already registered with windowsFonts(). 313 | " 314 | "2","Segoe Print already registered with windowsFonts(). 315 | " 316 | "2","Segoe Script already registered with windowsFonts(). 317 | " 318 | "2","Segoe UI already registered with windowsFonts(). 319 | " 320 | "2","Segoe UI Light already registered with windowsFonts(). 321 | " 322 | "2","Segoe UI Semibold already registered with windowsFonts(). 323 | " 324 | "2","Segoe UI Semilight already registered with windowsFonts(). 325 | " 326 | "2","Segoe UI Black already registered with windowsFonts(). 327 | " 328 | "2","Segoe UI Emoji already registered with windowsFonts(). 329 | " 330 | "2","Segoe UI Historic already registered with windowsFonts(). 331 | " 332 | "2","Segoe UI Symbol already registered with windowsFonts(). 333 | " 334 | "2","Showcard Gothic already registered with windowsFonts(). 335 | " 336 | "2","SimSun-ExtB already registered with windowsFonts(). 337 | " 338 | "2","Snap ITC already registered with windowsFonts(). 339 | " 340 | "2","Stencil already registered with windowsFonts(). 341 | " 342 | "2","Sylfaen already registered with windowsFonts(). 343 | " 344 | "2","Symbol already registered with windowsFonts(). 345 | " 346 | "2","Tahoma already registered with windowsFonts(). 347 | " 348 | "2","Tempus Sans ITC already registered with windowsFonts(). 349 | " 350 | "2","Times New Roman already registered with windowsFonts(). 351 | " 352 | "2","Trebuchet MS already registered with windowsFonts(). 353 | " 354 | "2","Tw Cen MT already registered with windowsFonts(). 355 | " 356 | "2","Tw Cen MT Condensed already registered with windowsFonts(). 357 | " 358 | "2","Tw Cen MT Condensed Extra Bold already registered with windowsFonts(). 359 | " 360 | "2","Verdana already registered with windowsFonts(). 361 | " 362 | "2","Viner Hand ITC already registered with windowsFonts(). 363 | " 364 | "2","Vivaldi already registered with windowsFonts(). 365 | " 366 | "2","Vladimir Script already registered with windowsFonts(). 367 | " 368 | "2","Webdings already registered with windowsFonts(). 369 | " 370 | "2","Wingdings already registered with windowsFonts(). 371 | " 372 | "2","Wingdings 2 already registered with windowsFonts(). 373 | " 374 | "2","Wingdings 3 already registered with windowsFonts(). 375 | " 376 | "0","windowsFonts(""Arial"" = windowsFont(""Calibri""))" 377 | -------------------------------------------------------------------------------- /Reporte Automático/.Rhistory: -------------------------------------------------------------------------------- 1 | output_file = paste0("Reporte_", region, "_", format(Sys.Date(), "%d%m%Y"), ".docx") 2 | ) 3 | filesstrings::file.move(paste0("Reporte_", region, "_", format(Sys.Date(), "%d%m%Y"), ".docx"), 4 | "Reportes por región/") 5 | } 6 | imprimir_reporte("Araucanía") 7 | rmarkdown::render( 8 | "ReportePorRegion.Rmd", 9 | params = list( 10 | reg = "Araucanía" 11 | ), 12 | encoding = "UTF-8", 13 | output_file = paste0("Reporte_", "Araucanía", "_", format(Sys.Date(), "%d%m%Y"), ".docx") 14 | ) 15 | # Crear función de reporte 16 | imprimir_reporte <- function(region) { 17 | rmarkdown::render( 18 | "ReportePorRegion.Rmd", 19 | params = list( 20 | reg = region 21 | ), 22 | encoding = "UTF-8", 23 | output_file = paste0("Reporte_", region, "_", format(Sys.Date(), "%d%m%Y"), ".docx") 24 | ) 25 | filesstrings::file.move(paste0("Reporte_", region, "_", format(Sys.Date(), "%d%m%Y"), ".docx"), 26 | "Reportes por región/") 27 | } 28 | imprimir_reporte("Araucanía") 29 | #Opciones 30 | regiones <- c("Tarapacá" 31 | , "Antofagasta" 32 | , "Atacama" 33 | , "Coquimbo" 34 | , "O'Higgins" 35 | , "Valparaíso" 36 | , "Maule" 37 | , "Biobío" 38 | , "Araucanía" 39 | , "Lagos" 40 | , "Aysén" 41 | , "Magallanes" 42 | , "Metropolitana" 43 | , "Ríos" 44 | , "Arica" 45 | , "Ñuble") 46 | for (i in regiones){ 47 | imprimir_reporte(i) 48 | } 49 | install.packages("odbc") 50 | install.packages("RSQLite") 51 | source("Scripts/Reg.R", encoding = "UTF-8") 52 | reg <- as.character(reg3[reg3$reg2 == params$reg, 1]) # esto facilita la impresión masiva de reportes 53 | source("Scripts/CargarLibrerias.R", encoding = "UTF-8") 54 | Resumen_UnidadFiscalizable <- 55 | read_excel("../Datos/Resumen_UnidadFiscalizable.xlsx") 56 | Datos_Instrumento <- 57 | read_excel("../Datos/Datos_Instrumento.xlsx") 58 | Detalle_ProcesoSancionUnidadFiscalizable <- 59 | read_excel("../Datos/Detalle_ProcesoSancionUnidadFiscalizable.xlsx") 60 | Datos_Sancion <- 61 | read_excel("../Datos/Datos_Sancion.xlsx") 62 | Datos_Sancion <- Datos_Sancion %>% 63 | mutate(RegionSelect = case_when( 64 | Region == reg ~ reg, 65 | TRUE ~ "Resto de las Regiones")) 66 | # Datos: UF por región 67 | UF_reg <- Resumen_UnidadFiscalizable %>% filter(RegionNombre == reg) 68 | resumen_reg <- Resumen_UnidadFiscalizable %>% 69 | group_by("Región" = RegionNombre) %>% 70 | summarise(UFs = n()) %>% 71 | arrange(desc(UFs)) %>% 72 | ungroup() %>% 73 | mutate(Porcentaje = round(UFs/sum(UFs)*100,1), 74 | Destacar = case_when(`Región` == reg ~ "Si", 75 | is.na(`Región`) ~ "Si2", 76 | TRUE ~ "No"), 77 | orden_reg = case_when( 78 | `Región` == "Región de Arica y Parinacota" ~ 17, 79 | `Región` == "Región de Tarapacá" ~ 16, 80 | `Región` == "Región de Antofagasta" ~ 15, 81 | `Región` == "Región de Atacama" ~ 14, 82 | `Región` == "Región de Coquimbo" ~ 13, 83 | `Región` == "Región Metropolitana" ~ 12, 84 | `Región` == "Región de Valparaíso" ~ 11, 85 | `Región` == "Región del Libertador General Bernardo O'Higgins" ~ 10, 86 | `Región` == "Región del Maule" ~ 9, 87 | `Región` == "Región de Ñuble" ~ 8, 88 | `Región` == "Región del Biobío" ~ 7, 89 | `Región` == "Región de la Araucanía" ~ 6, 90 | `Región` == "Región de Los Ríos" ~ 5, 91 | `Región` == "Región de los Lagos" ~ 4, 92 | `Región` == "Región de Aysén del General Carlos Ibañez del Campo" ~ 3, 93 | `Región` == "Región de Magallanes y la Antártica Chilena" ~ 2, 94 | is.na(`Región`) ~ 1 95 | )) 96 | Porcentaje_uf_reg <- filter(resumen_reg, `Región` == reg)[[3]] 97 | resumen_cate <- Resumen_UnidadFiscalizable %>% 98 | filter(RegionNombre == reg) %>% 99 | group_by("Categoría Económica" = CategoriaEconomicaNombre) %>% 100 | summarise(UFs = n()) %>% 101 | arrange(desc(UFs)) %>% 102 | ungroup() %>% 103 | mutate(Porcentaje = round(UFs/sum(UFs)*100,1), 104 | Destacar = case_when(is.na(`Categoría Económica`) ~ "Si", 105 | TRUE ~ "No")) 106 | top_RCA <- Datos_Instrumento %>% 107 | filter(SiglaInstrumento == "RCA", #Instrumento de inter?s 108 | NombreRegion == reg #Filtro región 109 | #Existen RCAs "interregionales" que en "NombreRegionPoryecto" especifican región (acá se consideran) 110 | | (NombreRegion == "Interregional" & NombreRegionProyecto == reg)) %>% # | signfica "o" 111 | group_by(CategoriaEconomicaNombre) %>% 112 | summarise(RCAs = n()) %>% 113 | arrange(desc(RCAs)) %>% 114 | top_n(5) 115 | Datos_Instrumento %>% 116 | filter(SiglaInstrumento == "RCA", #Instrumento de inter?s 117 | NombreRegion == reg #Filtro región 118 | #Existen RCAs "interregionales" que en "NombreRegionPoryecto" especifican región (acá se consideran) 119 | | (NombreRegion == "Interregional" & NombreRegionProyecto == reg)) 120 | Datos_Instrumento 121 | Datos_Instrumento %>% 122 | filter(SiglaInstrumento == "RCA" 123 | ) 124 | Datos_Instrumento %>% 125 | filter(SiglaInstrumento == "RCA", #Instrumento de inter?s 126 | NombreRegion == reg 127 | ) 128 | reg 129 | Datos_Instrumento %>% distinct(NombreRegion) 130 | Datos_Instrumento 131 | View(Datos_Instrumento) 132 | read_excel("../Datos/Datos_Instrumento.xlsx") 133 | Datos_Instrumento <- 134 | read_excel("../Datos/Datos_Instrumento.xlsx") 135 | Datos_Instrumento %>% distinct(NombreRegion) 136 | Datos_Instrumento <- 137 | read_excel("../Datos/Datos_Instrumento.xlsx") 138 | View(Datos_Instrumento) 139 | source('~/GitHub/Reportes-automaticos/Reporte Automático/Scripts/CargaDatos.R', echo=TRUE) 140 | source("Scripts/ManejoDatos_UF.R", encoding = "UTF-8") 141 | source("Scripts/ManejoDatos_FDC.R", encoding = "UTF-8") 142 | source("Scripts/Graficos.R", encoding = "UTF-8") 143 | uf_reg 144 | uf_cat 145 | top_RCA %>% 146 | kable(format = "markdown") 147 | source('~/GitHub/Reportes-automaticos/Reporte Automático/Scripts/CargarLibrerias.R', echo=TRUE) 148 | source('~/GitHub/Reportes-automaticos/Reporte Automático/Scripts/CargarLibrerias.R', echo=TRUE) 149 | source("Scripts/Reg.R", encoding = "UTF-8") 150 | reg <- as.character(reg3[reg3$reg2 == params$reg, 1]) # esto facilita la impresión masiva de reportes 151 | source("Scripts/CargaDatos.R", encoding = "UTF-8") 152 | coord_uf <- Resumen_UnidadFiscalizable %>% 153 | select("RegionNombre", "Latitud", "Longitud") %>% 154 | filter(RegionNombre == reg, !is.na(Latitud), !is.na(Longitud)) 155 | if (reg == "Región de Aysén del General Carlos Ibáñez del Campo"){ 156 | long <- unique(coord_uf$Longitud_reg) 157 | ltd <- unique(coord_uf$Latitud_reg) 158 | } else { 159 | long <- filter(centroides, Region == reg)$longitud 160 | ltd <- filter(centroides, Region == reg)$latitud 161 | } 162 | centroides <- tribble( 163 | ~Region, ~latitud, ~longitud, 164 | "Región de Arica y Parinacota", -18.496932, -69.62854, 165 | "Región de Tarapacá", -20.215794, -69.393066, 166 | "Región de Antofagasta", -23.53599, -69.119139, 167 | "Región de Atacama", -27.395285, -69.910141, 168 | "Región de Coquimbo", -30.619033, -70.860692, 169 | "Región de Valparaíso", -32.782424, -70.959617, 170 | "Región Metropolitana", -33.604344, -70.627063, 171 | "Región del Libertador General Bernardo O'Higgins", -34.435366, -71.046566, 172 | "Región del Maule", -35.62133, -71.445649, 173 | "Región de Ñuble", -36.645411, -71.974643, 174 | "Región del Biobío", -37.500562, -72.392417, 175 | "Región de la Araucanía", -38.649155, -72.27425, 176 | "Región de Los Ríos", -40.004982, -72.570862, 177 | "Región de los Lagos", -42.04281, -72.89418, 178 | "Región de Aysén del General Carlos Ibáñez del Campo", -46.416524, -73.257083, 179 | "Región de Magallanes y la Antártica Chilena", -52.488319, -71.873603 180 | ) 181 | coord_uf <- Resumen_UnidadFiscalizable %>% 182 | select("RegionNombre", "Latitud", "Longitud") %>% 183 | filter(RegionNombre == reg, !is.na(Latitud), !is.na(Longitud)) 184 | if (reg == "Región de Aysén del General Carlos Ibáñez del Campo"){ 185 | long <- unique(coord_uf$Longitud_reg) 186 | ltd <- unique(coord_uf$Latitud_reg) 187 | } else { 188 | long <- filter(centroides, Region == reg)$longitud 189 | ltd <- filter(centroides, Region == reg)$latitud 190 | } 191 | if (reg %in% c("Región de Antofagasta", "Región de Atacama", "Región de Coquimbo", "Región de los Lagos", 192 | "Región de Aysén del General Carlos Ibáñez del Campo", "Región de Magallanes y la Antártica Chilena")){ 193 | z <- 7 194 | } else { 195 | z <- 8 196 | } 197 | leaflet(coord_uf) %>% 198 | setView(lng = long, lat = ltd, zoom = z) %>% 199 | addProviderTiles(providers$CartoDB.Positron) %>% 200 | addCircleMarkers(~Longitud, ~Latitud, color = "red", weight = 1, radius = 3) 201 | m <- leaflet(coord_uf) %>% 202 | setView(lng = long, lat = ltd, zoom = z) %>% 203 | addProviderTiles(providers$CartoDB.Positron) %>% 204 | addCircleMarkers(~Longitud, ~Latitud, color = "red", weight = 1, radius = 3) 205 | ?mapshot 206 | mapshot(m, file = "mapa.png") 207 | mapshot(m, file = "~/mapa.png") 208 | file.move("~/mapa.png", overwrite = TRUE) 209 | lista_paquetes <- c("dplyr", "ggplot2", "lubridate", "tidyr", "kableExtra", "flextable", "filesstring", 210 | "purrr", "readr", "extrafont", "stringr", "ggmap", "readxl", "leaflet", "mapview") 211 | nuevos_paquetes <- lista_paquetes[!(lista_paquetes %in% installed.packages()[,"Package"])] 212 | lapply(nuevos_paquetes, install.packages); lapply(lista_paquetes, require, character.only = TRUE) 213 | rm(lista_paquetes, nuevos_paquetes) 214 | lista_paquetes <- c("dplyr", "ggplot2", "lubridate", "tidyr", "kableExtra", "flextable", "filesstrings", 215 | "purrr", "readr", "extrafont", "stringr", "ggmap", "readxl", "leaflet", "mapview") 216 | nuevos_paquetes <- lista_paquetes[!(lista_paquetes %in% installed.packages()[,"Package"])] 217 | lapply(nuevos_paquetes, install.packages); lapply(lista_paquetes, require, character.only = TRUE) 218 | rm(lista_paquetes, nuevos_paquetes) 219 | loadfonts() 220 | ?file.move 221 | file.move("~/mapa.png", overwrite = TRUE) 222 | file.move("~/mapa.png", "", overwrite = TRUE) 223 | file.move("~/mapa.png", "Mapa/", overwrite = TRUE) 224 | knitr::include_graphics("Mapa/mapa.png") 225 | knitr::include_graphics("Mapa/mapa.png") 226 | knitr::include_graphics("Mapa/mapa.png") 227 | FDC_cate 228 | source("Scripts/Reg.R", encoding = "UTF-8") 229 | reg <- as.character(reg3[reg3$reg2 == params$reg, 1]) # esto facilita la impresión masiva de reportes 230 | knitr::opts_chunk$set(echo = FALSE, message=FALSE, warning=FALSE, dpi=300) 231 | source("Scripts/CargarLibrerias.R", encoding = "UTF-8") 232 | source("Scripts/CargaDatos.R", encoding = "UTF-8") 233 | source("Scripts/ManejoDatos_UF.R", encoding = "UTF-8") 234 | source("Scripts/ManejoDatos_FDC.R", encoding = "UTF-8") 235 | source("Scripts/Graficos.R", encoding = "UTF-8") 236 | knitr::include_graphics("Mapa/mapa.png") 237 | uf_reg 238 | uf_cat 239 | top_RCA %>% 240 | flextable() %>% 241 | width(j = c(1, 2), width = c(1.8, 1)) %>% 242 | font(fontname = "Calibri", part = "all") %>% 243 | fontsize(size = 10, part = "all") 244 | source("Scripts/Reg.R", encoding = "UTF-8") 245 | reg <- as.character(reg3[reg3$reg2 == params$reg, 1]) # esto facilita la impresión masiva de reportes 246 | knitr::opts_chunk$set(echo = FALSE, message=FALSE, warning=FALSE, dpi=300) 247 | source("Scripts/CargarLibrerias.R", encoding = "UTF-8") 248 | source("Scripts/CargaDatos.R", encoding = "UTF-8") 249 | source("Scripts/ManejoDatos_UF.R", encoding = "UTF-8") 250 | source("Scripts/ManejoDatos_FDC.R", encoding = "UTF-8") 251 | source("Scripts/Graficos.R", encoding = "UTF-8") 252 | knitr::include_graphics("Mapa/mapa.png") 253 | uf_reg 254 | uf_cat 255 | top_RCA %>% 256 | flextable() %>% 257 | width(j = c(1, 2), width = c(1.8, 1)) %>% 258 | font(fontname = "Calibri", part = "all") %>% 259 | fontsize(size = 10, part = "all") 260 | fdc_reg 261 | fdc_anio 262 | fdc_cat 263 | fdc_origen 264 | fdc_estado 265 | knitr::include_graphics("Mapa/mapa.png") 266 | knitr::include_graphics("Mapa/mapa.png") 267 | knitr::include_graphics("Mapa/mapa.png") 268 | knitr::include_graphics("Mapa/mapa.png") 269 | source("Scripts/Mapa.R", encoding = "UTF-8") 270 | ?render 271 | imprimir_reporte <- function(x){ 272 | rmarkdown::render("ReportePorRegion.Rmd", 273 | params = list(reg = x)) 274 | } 275 | source('~/GitHub/Reportes-automaticos/Reporte Automático/Scripts/CargarLibrerias.R', encoding = 'UTF-8', echo=TRUE) 276 | ?walk 277 | imprimir_reporte <- function(x){ 278 | rmarkdown::render("ReportePorRegion.Rmd", 279 | params = list(reg = x), 280 | output_file = paste0("Reporte_", x)) 281 | } 282 | regiones <- c("Tarapacá", "Antofagasta", "Atacama", "Coquimbo", "O'Higgins", 283 | "Valparaíso", "Maule", "Biobío", "Araucanía", "Lagos", "Aysén", 284 | "Magallanes", "Metropolitana", "Ríos", "Arica", "Ñuble") 285 | walk(regiones, imprimir_reporte) 286 | # Definir función para generación de reportes 287 | imprimir_reporte <- function(x){ 288 | rmarkdown::render("ReportePorRegion.Rmd", 289 | params = list(reg = x), 290 | output_file = paste0("Reportes/Reporte_", x)) 291 | } 292 | # Valores que se usarán como "parámetros" (variables) del reporte 293 | regiones <- c("Tarapacá", "Antofagasta", "Atacama", "Coquimbo", "O'Higgins", 294 | "Valparaíso", "Maule", "Biobío", "Araucanía", "Lagos", "Aysén", 295 | "Magallanes", "Metropolitana", "Ríos", "Arica", "Ñuble") 296 | # Aplicar la función a cada valor de "regiones" 297 | walk(regiones, imprimir_reporte) 298 | # Aplicar la función a cada valor de "regiones" 299 | walk(regiones, imprimir_reporte) 300 | format(Sys.Date(), "%d/%m/%Y") 301 | knit_with_parameters('~/GitHub/Reportes-automaticos/Reporte Automático/ReportePorRegion.Rmd', encoding = 'UTF-8') 302 | knit_with_parameters('~/GitHub/Reportes-automaticos/Reporte Automático/ReportePorRegion.Rmd', encoding = 'UTF-8') 303 | knit_with_parameters('~/GitHub/Reportes-automaticos/Reporte Automático/ReportePorRegion.Rmd', encoding = 'UTF-8') 304 | source('~/GitHub/Reportes-automaticos/Reporte Automático/ImprimirReportes.R', encoding = 'UTF-8', echo=TRUE) 305 | source('~/GitHub/Reportes-automaticos/Reporte Automático/ImprimirReportes.R', encoding = 'UTF-8', echo=TRUE) 306 | source('~/GitHub/Reportes-automaticos/Reporte Automático/ImprimirReportes.R', encoding = 'UTF-8', echo=TRUE) 307 | source('~/GitHub/Reportes-automaticos/Reporte Automático/ImprimirReportes.R', encoding = 'UTF-8', echo=TRUE) 308 | x 309 | regiones 310 | rmarkdown::render("ReportePorRegion.Rmd", 311 | params = list(reg = "Tarapacá"), 312 | output_file = paste0("Reportes/Reporte_", "Tarapacá")) 313 | # Definir función para generación de reportes 314 | imprimir_reporte <- function(x){ 315 | rmarkdown::render("ReportePorRegion.Rmd", 316 | params = list(reg = x), 317 | output_file = paste0("Reportes/Reporte_", x)) 318 | } 319 | # Valores que se usarán como "parámetros" (variables) del reporte 320 | regiones <- c("Tarapacá", "Antofagasta", "Atacama", "Coquimbo", "O'Higgins", 321 | "Valparaíso", "Maule", "Biobío", "Araucanía", "Lagos", "Aysén", 322 | "Magallanes", "Metropolitana", "Ríos", "Arica", "Ñuble") 323 | imprimir_reporte 324 | regiones 325 | # Aplicar la función a cada valor de "regiones" 326 | walk(regiones, imprimir_reporte) 327 | format(Sys.Date(), "%d-%m-%Y") 328 | format(Sys.Date(), "%d-%m-%Y") 329 | # Definir función para generación de reportes 330 | imprimir_reporte <- function(x){ 331 | rmarkdown::render("ReportePorRegion.Rmd", 332 | params = list(reg = x), 333 | output_file = paste0("Reportes/Reporte_", x, "_", format(Sys.Date(), "%d-%m-%Y")) 334 | ) 335 | } 336 | # Valores que se usarán como "parámetros" (variables) del reporte 337 | regiones <- c("Tarapacá", "Antofagasta", "Atacama", "Coquimbo", "O'Higgins", 338 | "Valparaíso", "Maule", "Biobío", "Araucanía", "Lagos", "Aysén", 339 | "Magallanes", "Metropolitana", "Ríos", "Arica", "Ñuble") 340 | # Aplicar la función a cada valor de "regiones" 341 | walk(regiones, imprimir_reporte) 342 | source("Scripts/CargarLibrerias.R", encoding = "UTF-8") 343 | source("Scripts/Reg.R", encoding = "UTF-8") 344 | reg <- as.character(reg3[reg3$reg2 == params$reg, 1]) # esto facilita la impresión masiva de reportes 345 | knitr::opts_chunk$set(echo = FALSE, message=FALSE, warning=FALSE, dpi=300) 346 | source("Scripts/CargaDatos.R", encoding = "UTF-8") 347 | source("Scripts/ManejoDatos_UF.R", encoding = "UTF-8") 348 | source("Scripts/ManejoDatos_FDC.R", encoding = "UTF-8") 349 | source("Scripts/Graficos.R", encoding = "UTF-8") 350 | source("Scripts/Mapa.R", encoding = "UTF-8") 351 | knitr::include_graphics("Mapa/mapa.png") 352 | uf_reg 353 | uf_cat 354 | top_RCA %>% 355 | flextable() %>% 356 | width(j = c(1, 2), width = c(1.8, 1)) %>% 357 | font(fontname = "Calibri", part = "all") %>% 358 | fontsize(size = 10, part = "all") 359 | fdc_reg 360 | fdc_anio 361 | fdc_cat 362 | fdc_origen 363 | fdc_estado 364 | fdc_cat 365 | windowsFonts("Arial" = windowsFont("Arial")) 366 | windowsFonts("Arial" = windowsFont("Clibri")) 367 | windowsFonts("Arial" = windowsFont("Calibri")) 368 | source("Scripts/CargarLibrerias.R", encoding = "UTF-8") 369 | windowsFonts("Arial" = windowsFont("Calibri")) 370 | source("Scripts/Reg.R", encoding = "UTF-8") 371 | reg <- as.character(reg3[reg3$reg2 == params$reg, 1]) # esto facilita la impresión masiva de reportes 372 | knitr::opts_chunk$set(echo = FALSE, message=FALSE, warning=FALSE, dpi=300) 373 | source("Scripts/CargaDatos.R", encoding = "UTF-8") 374 | source("Scripts/ManejoDatos_UF.R", encoding = "UTF-8") 375 | source("Scripts/ManejoDatos_FDC.R", encoding = "UTF-8") 376 | source("Scripts/Graficos.R", encoding = "UTF-8") 377 | source("Scripts/Mapa.R", encoding = "UTF-8") 378 | knitr::include_graphics("Mapa/mapa.png") 379 | uf_reg 380 | uf_cat 381 | top_RCA %>% 382 | flextable() %>% 383 | width(j = c(1, 2), width = c(1.8, 1)) %>% 384 | font(fontname = "Calibri", part = "all") %>% 385 | fontsize(size = 10, part = "all") 386 | fdc_reg 387 | fdc_anio 388 | fdc_cat 389 | fdc_origen 390 | fdc_estado 391 | windowFonts() 392 | windowsFonts() 393 | loadfonts() 394 | loadfonts(device = "win") 395 | font_import() 396 | 2+2 397 | loadfonts(device = "win") 398 | loadfonts(device = "win") 399 | loadfonts(device = "win") 400 | uf_cat 401 | knitr::opts_chunk$set(echo = FALSE, message=FALSE, warning=FALSE, dpi=300) 402 | source("Scripts/CargaDatos.R", encoding = "UTF-8") 403 | source("Scripts/ManejoDatos_UF.R", encoding = "UTF-8") 404 | source("Scripts/ManejoDatos_FDC.R", encoding = "UTF-8") 405 | source("Scripts/Graficos.R", encoding = "UTF-8") 406 | source("Scripts/Mapa.R", encoding = "UTF-8") 407 | knitr::include_graphics("Mapa/mapa.png") 408 | uf_reg 409 | uf_cat 410 | top_RCA %>% 411 | flextable() %>% 412 | width(j = c(1, 2), width = c(1.8, 1)) %>% 413 | font(fontname = "Calibri", part = "all") %>% 414 | fontsize(size = 10, part = "all") 415 | fdc_reg 416 | fdc_anio 417 | fdc_cat 418 | fdc_origen 419 | fdc_estado 420 | source("Scripts/CargarLibrerias.R", encoding = "UTF-8") 421 | windowsFonts("Arial" = windowsFont("Calibri")) 422 | source("Scripts/Reg.R", encoding = "UTF-8") 423 | reg <- as.character(reg3[reg3$reg2 == params$reg, 1]) # esto facilita la impresión masiva de reportes 424 | source("Scripts/CargaDatos.R", encoding = "UTF-8") 425 | View(Resumen_UnidadFiscalizable) 426 | params$rreg 427 | params$reg 428 | library(purrr) 429 | # Definir función para generación de reportes 430 | imprimir_reporte <- function(x){ 431 | rmarkdown::render("ReportePorRegion.Rmd", 432 | params = list(reg = x), 433 | output_file = paste0("Reportes/Reporte_", x, "_", format(Sys.Date(), "%d-%m-%Y")) 434 | ) 435 | } 436 | # Valores que se usarán como "parámetros" (variables) del reporte 437 | regiones <- c("Tarapacá", "Antofagasta", "Atacama", "Coquimbo", "O'Higgins", 438 | "Valparaíso", "Maule", "Biobío", "Araucanía", "Lagos", "Aysén", 439 | "Magallanes", "Metropolitana", "Ríos", "Arica", "Ñuble") 440 | # Aplicar la función a cada valor de "regiones" 441 | walk(regiones, imprimir_reporte) 442 | library(purrr) 443 | # Definir función para generación de reportes 444 | imprimir_reporte <- function(x){ 445 | rmarkdown::render("ReportePorRegion.Rmd", 446 | params = list(reg = x), 447 | output_file = paste0("Reportes/Reporte_", x, "_", format(Sys.Date(), "%d-%m-%Y")) 448 | ) 449 | } 450 | # Valores que se usarán como "parámetros" (variables) del reporte 451 | regiones <- c("Tarapacá", "Antofagasta", "Atacama", "Coquimbo", "O'Higgins", 452 | "Valparaíso", "Maule", "Biobío", "Araucanía", "Lagos", "Aysén", 453 | "Magallanes", "Metropolitana", "Ríos", "Arica", "Ñuble") 454 | # Aplicar la función a cada valor de "regiones" 455 | walk(regiones, imprimir_reporte) 456 | source('~/GitHub/Reportes-automaticos/Reporte Automático/ImprimirReportes.R', encoding = 'UTF-8', echo=TRUE) 457 | source('~/GitHub/Reportes-automaticos/Reporte Automático/ImprimirReportes.R', encoding = 'UTF-8', echo=TRUE) 458 | source('~/GitHub/Reportes-automaticos/Reporte Automático/ImprimirReportes.R', encoding = 'UTF-8', echo=TRUE) 459 | # Valores que se usarán como "parámetros" (variables) del reporte 460 | regiones <- c("Tarapacá", "Antofagasta", "Atacama", "Coquimbo", "O'Higgins", 461 | "Valparaíso", "Maule", "Biobío", "Araucanía", "Lagos", "Aysén", 462 | "Magallanes", "Metropolitana", "Ríos", "Arica", "Ñuble") 463 | # Definir función para generación de reportes 464 | for (i in regiones){ 465 | rmarkdown::render("ReportePorRegion.Rmd", 466 | params = list(reg = i), 467 | output_file = paste0("Reportes/Reporte_", i, "_", format(Sys.Date(), "%d-%m-%Y")) 468 | ) 469 | } 470 | source('~/GitHub/Reportes-automaticos/Reporte Automático/ImprimirReportes.R', encoding = 'UTF-8', echo=TRUE) 471 | source("Scripts/CargarLibrerias.R", encoding = "UTF-8") 472 | windowsFonts("Arial" = windowsFont("Calibri")) 473 | source("Scripts/Reg.R", encoding = "UTF-8") 474 | reg <- as.character(reg3[reg3$reg2 == params$reg, 1]) # esto facilita la impresión masiva de reportes 475 | source('~/GitHub/Reportes-automaticos/Reporte Automático/Scripts/CargaDatos.R', echo=TRUE) 476 | View(Resumen_UnidadFiscalizable) 477 | View(Datos_Instrumento) 478 | View(Detalle_ProcesoSancionUnidadFiscalizable) 479 | View(Datos_Sancion) 480 | source('~/GitHub/Reportes-automaticos/Reporte Automático/ImprimirReportes.R', encoding = 'UTF-8', echo=TRUE) 481 | knitr::opts_chunk$set(echo = FALSE, message=FALSE, warning=FALSE, dpi=300) 482 | source("Scripts/CargarLibrerias.R", encoding = "UTF-8") 483 | windowsFonts("Arial" = windowsFont("Calibri")) 484 | source("Scripts/Reg.R", encoding = "UTF-8") 485 | reg <- as.character(reg3[reg3$reg2 == params$reg, 1]) # esto facilita la impresión masiva de reportes 486 | source("Scripts/CargaDatos.R", encoding = "UTF-8") 487 | source("Scripts/ManejoDatos_UF.R", encoding = "UTF-8") 488 | source("Scripts/ManejoDatos_FDC.R", encoding = "UTF-8") 489 | source("Scripts/Graficos.R", encoding = "UTF-8") 490 | source("Scripts/Mapa.R", encoding = "UTF-8") 491 | knitr::include_graphics("Mapa/mapa.png") 492 | uf_reg 493 | uf_cat 494 | top_RCA %>% 495 | flextable() %>% 496 | width(j = c(1, 2), width = c(1.8, 1)) %>% 497 | font(fontname = "Calibri", part = "all") %>% 498 | fontsize(size = 10, part = "all") 499 | top_RCA %>% 500 | flextable() %>% 501 | width(j = c(1, 2), width = c(1.8, 1)) %>% 502 | font(fontname = "Calibri", part = "all") %>% 503 | fontsize(size = 10, part = "all") 504 | top_RCA %>% 505 | flextable() %>% 506 | width(j = c(1, 2), width = c(1.8, 1)) %>% 507 | font(fontname = "Calibri", part = "all") %>% 508 | fontsize(size = 10, part = "all") 509 | fdc_reg 510 | reg 511 | prettyNum(nrow(UF_reg), big.mark = ".", decimal.mark = ",") 512 | resumen_cate[2,2] 513 | --------------------------------------------------------------------------------