diff --git a/incidencia_delictiva_nac/01_poblacion.xls b/01_incidencia_delictiva_nac/01_poblacion.xls similarity index 100% rename from incidencia_delictiva_nac/01_poblacion.xls rename to 01_incidencia_delictiva_nac/01_poblacion.xls diff --git a/incidencia_delictiva_nac/Estatal-Delitos - diciembre 2019.xlsb b/01_incidencia_delictiva_nac/Estatal-Delitos - diciembre 2019.xlsb similarity index 100% rename from incidencia_delictiva_nac/Estatal-Delitos - diciembre 2019.xlsb rename to 01_incidencia_delictiva_nac/Estatal-Delitos - diciembre 2019.xlsb diff --git a/incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.dbf b/01_incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.dbf similarity index 100% rename from incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.dbf rename to 01_incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.dbf diff --git a/incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.html b/01_incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.html similarity index 100% rename from incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.html rename to 01_incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.html diff --git a/incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.png b/01_incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.png similarity index 100% rename from incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.png rename to 01_incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.png diff --git a/incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.prj b/01_incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.prj similarity index 100% rename from incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.prj rename to 01_incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.prj diff --git a/incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.shp b/01_incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.shp similarity index 100% rename from incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.shp rename to 01_incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.shp diff --git a/incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.shx b/01_incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.shx similarity index 100% rename from incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.shx rename to 01_incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.shx diff --git a/incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.xml b/01_incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.xml similarity index 100% rename from incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.xml rename to 01_incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw.xml diff --git a/incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw_s.png b/01_incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw_s.png similarity index 100% rename from incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw_s.png rename to 01_incidencia_delictiva_nac/destdv250k_2gw/destdv250k_2gw_s.png diff --git a/incidencia_delictiva_nac/inc_delic_anio_mex.pdf b/01_incidencia_delictiva_nac/inc_delic_anio_mex.pdf similarity index 100% rename from incidencia_delictiva_nac/inc_delic_anio_mex.pdf rename to 01_incidencia_delictiva_nac/inc_delic_anio_mex.pdf diff --git a/incidencia_delictiva_nac/practica_1.R b/01_incidencia_delictiva_nac/practica_1.R similarity index 99% rename from incidencia_delictiva_nac/practica_1.R rename to 01_incidencia_delictiva_nac/practica_1.R index 84dad94..64a4c37 100644 --- a/incidencia_delictiva_nac/practica_1.R +++ b/01_incidencia_delictiva_nac/practica_1.R @@ -6,7 +6,7 @@ library(dplyr) library(stringr) library(sf) library(cartography) -setwd("incidencia_delictiva_nac/") +setwd("01_incidencia_delictiva_nac/") # Incidencia delictiva del fuero común # Fuente: Secretariado Ejecutivo del Sistema Nacional de Seguridad Pública diff --git a/incidencia_delictiva_nac/practica_1.pdf b/01_incidencia_delictiva_nac/practica_1.pdf similarity index 100% rename from incidencia_delictiva_nac/practica_1.pdf rename to 01_incidencia_delictiva_nac/practica_1.pdf diff --git a/02_otec/ESTADOS/ESTADOS.dbf b/02_otec/ESTADOS/ESTADOS.dbf new file mode 100644 index 0000000..22d4afd Binary files /dev/null and b/02_otec/ESTADOS/ESTADOS.dbf differ diff --git a/02_otec/ESTADOS/ESTADOS.prj b/02_otec/ESTADOS/ESTADOS.prj new file mode 100644 index 0000000..329bc59 --- /dev/null +++ b/02_otec/ESTADOS/ESTADOS.prj @@ -0,0 +1 @@ +PROJCS["North_America_Lambert_Conformal_Conic",GEOGCS["ITRF_1992",DATUM["D_ITRF_1992",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",2500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-102.0],PARAMETER["Standard_Parallel_1",17.5],PARAMETER["Standard_Parallel_2",29.5],PARAMETER["Latitude_Of_Origin",12.0],UNIT["Meter",1.0]] \ No newline at end of file diff --git a/02_otec/ESTADOS/ESTADOS.shp b/02_otec/ESTADOS/ESTADOS.shp new file mode 100644 index 0000000..fda1cd5 Binary files /dev/null and b/02_otec/ESTADOS/ESTADOS.shp differ diff --git a/02_otec/ESTADOS/ESTADOS.shx b/02_otec/ESTADOS/ESTADOS.shx new file mode 100644 index 0000000..4b9e5fd Binary files /dev/null and b/02_otec/ESTADOS/ESTADOS.shx differ diff --git a/02_otec/ESTADOS/mexico.cpg b/02_otec/ESTADOS/mexico.cpg new file mode 100644 index 0000000..3ad133c --- /dev/null +++ b/02_otec/ESTADOS/mexico.cpg @@ -0,0 +1 @@ +UTF-8 \ No newline at end of file diff --git a/02_otec/ESTADOS/mexico.dbf b/02_otec/ESTADOS/mexico.dbf new file mode 100644 index 0000000..c4881ce Binary files /dev/null and b/02_otec/ESTADOS/mexico.dbf differ diff --git a/02_otec/ESTADOS/mexico.prj b/02_otec/ESTADOS/mexico.prj new file mode 100644 index 0000000..408a693 --- /dev/null +++ b/02_otec/ESTADOS/mexico.prj @@ -0,0 +1 @@ +PROJCS["Lambert_Conformal_Conic",GEOGCS["GCS_GRS 1980(IUGG, 1980)",DATUM["D_unknown",SPHEROID["GRS80",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["standard_parallel_1",17.5],PARAMETER["standard_parallel_2",29.5],PARAMETER["latitude_of_origin",12],PARAMETER["central_meridian",-102],PARAMETER["false_easting",2500000],PARAMETER["false_northing",0],UNIT["Meter",1]] \ No newline at end of file diff --git a/02_otec/ESTADOS/mexico.qpj b/02_otec/ESTADOS/mexico.qpj new file mode 100644 index 0000000..e86e90d --- /dev/null +++ b/02_otec/ESTADOS/mexico.qpj @@ -0,0 +1 @@ +PROJCS["unnamed",GEOGCS["GRS 1980(IUGG, 1980)",DATUM["unknown",SPHEROID["GRS80",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",17.5],PARAMETER["standard_parallel_2",29.5],PARAMETER["latitude_of_origin",12],PARAMETER["central_meridian",-102],PARAMETER["false_easting",2500000],PARAMETER["false_northing",0],UNIT["Meter",1]] diff --git a/02_otec/ESTADOS/mexico.shp b/02_otec/ESTADOS/mexico.shp new file mode 100644 index 0000000..3335ed2 Binary files /dev/null and b/02_otec/ESTADOS/mexico.shp differ diff --git a/02_otec/ESTADOS/mexico.shx b/02_otec/ESTADOS/mexico.shx new file mode 100644 index 0000000..91d1252 Binary files /dev/null and b/02_otec/ESTADOS/mexico.shx differ diff --git a/02_otec/PracticaOTEC.R b/02_otec/PracticaOTEC.R new file mode 100644 index 0000000..8c1f4f5 --- /dev/null +++ b/02_otec/PracticaOTEC.R @@ -0,0 +1,26 @@ +# Práctica: OTEC +library(raster) +library(rgdal) +library(sf) +library(tmap) + +# Polígonos estatales +estados <- read_sf("ESTADOS/ESTADOS.shp") + +# Batimetría del Mar Caribe +# Fuente: NOAA +batimetria <- raster("etopo1_bedrock.tif") + +pais <- st_union(estados) +buffer <- st_buffer(pais, dist=15000) + +buffer + +nivel <- calc(batimetria, function(x) { if (x == -700 || x == -800 || x == -900 || x == -1000) x else 0 }) + +tm_shape(nivel) + + tm_raster() + + tm_shape(pais) + + tm_polygons(alpha = 0.5) + + tm_shape(buffer) + + tm_polygons(alpha = 0.5) diff --git a/02_otec/PracticaOTEC.pdf b/02_otec/PracticaOTEC.pdf new file mode 100644 index 0000000..e6b54ff Binary files /dev/null and b/02_otec/PracticaOTEC.pdf differ diff --git a/02_otec/etopo1_bedrock.tif b/02_otec/etopo1_bedrock.tif new file mode 100644 index 0000000..f8f6eed Binary files /dev/null and b/02_otec/etopo1_bedrock.tif differ diff --git a/renv/activate.R b/renv/activate.R index 46077e4..4baa934 100644 --- a/renv/activate.R +++ b/renv/activate.R @@ -1,185 +1,185 @@ - -local({ - - # the requested version of renv - version <- "0.9.3" - - # avoid recursion - if (!is.na(Sys.getenv("RENV_R_INITIALIZING", unset = NA))) - return(invisible(TRUE)) - - # signal that we're loading renv during R startup - Sys.setenv("RENV_R_INITIALIZING" = "true") - on.exit(Sys.unsetenv("RENV_R_INITIALIZING"), add = TRUE) - - # signal that we've consented to use renv - options(renv.consent = TRUE) - - # load the 'utils' package eagerly -- this ensures that renv shims, which - # mask 'utils' packages, will come first on the search path - library(utils, lib.loc = .Library) - - # check to see if renv has already been loaded - if ("renv" %in% loadedNamespaces()) { - - # if renv has already been loaded, and it's the requested version of renv, - # nothing to do - spec <- .getNamespaceInfo(.getNamespace("renv"), "spec") - if (identical(spec[["version"]], version)) - return(invisible(TRUE)) - - # otherwise, unload and attempt to load the correct version of renv - unloadNamespace("renv") - - } - - # construct path to renv in library - libpath <- local({ - - root <- Sys.getenv("RENV_PATHS_LIBRARY", unset = "renv/library") - prefix <- paste("R", getRversion()[1, 1:2], sep = "-") - - # include SVN revision for development versions of R - # (to avoid sharing platform-specific artefacts with released versions of R) - devel <- - identical(R.version[["status"]], "Under development (unstable)") || - identical(R.version[["nickname"]], "Unsuffered Consequences") - - if (devel) - prefix <- paste(prefix, R.version[["svn rev"]], sep = "-r") - - file.path(root, prefix, R.version$platform) - - }) - - # try to load renv from the project library - if (requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) { - - # warn if the version of renv loaded does not match - loadedversion <- utils::packageDescription("renv", fields = "Version") - if (version != loadedversion) { - - # assume four-component versions are from GitHub; three-component - # versions are from CRAN - components <- strsplit(loadedversion, "[.-]")[[1]] - remote <- if (length(components) == 4L) - paste("rstudio/renv", loadedversion, sep = "@") - else - paste("renv", loadedversion, sep = "@") - - fmt <- paste( - "renv %1$s was loaded from project library, but renv %2$s is recorded in lockfile.", - "Use `renv::record(\"%3$s\")` to record this version in the lockfile.", - "Use `renv::restore(packages = \"renv\")` to install renv %2$s into the project library.", - sep = "\n" - ) - - msg <- sprintf(fmt, loadedversion, version, remote) - warning(msg, call. = FALSE) - - } - - # load the project - return(renv::load()) - - } - - # failed to find renv locally; we'll try to install from GitHub. - # first, set up download options as appropriate (try to use GITHUB_PAT) - install_renv <- function() { - - message("Failed to find installation of renv -- attempting to bootstrap...") - - # ensure .Rprofile doesn't get executed - rpu <- Sys.getenv("R_PROFILE_USER", unset = NA) - Sys.setenv(R_PROFILE_USER = "") - on.exit({ - if (is.na(rpu)) - Sys.unsetenv("R_PROFILE_USER") - else - Sys.setenv(R_PROFILE_USER = rpu) - }, add = TRUE) - - # prepare download options - pat <- Sys.getenv("GITHUB_PAT") - if (nzchar(Sys.which("curl")) && nzchar(pat)) { - fmt <- "--location --fail --header \"Authorization: token %s\"" - extra <- sprintf(fmt, pat) - saved <- options("download.file.method", "download.file.extra") - options(download.file.method = "curl", download.file.extra = extra) - on.exit(do.call(base::options, saved), add = TRUE) - } else if (nzchar(Sys.which("wget")) && nzchar(pat)) { - fmt <- "--header=\"Authorization: token %s\"" - extra <- sprintf(fmt, pat) - saved <- options("download.file.method", "download.file.extra") - options(download.file.method = "wget", download.file.extra = extra) - on.exit(do.call(base::options, saved), add = TRUE) - } - - # fix up repos - repos <- getOption("repos") - on.exit(options(repos = repos), add = TRUE) - repos[repos == "@CRAN@"] <- "https://cloud.r-project.org" - options(repos = repos) - - # check for renv on CRAN matching this version - db <- as.data.frame(available.packages(), stringsAsFactors = FALSE) - if ("renv" %in% rownames(db)) { - entry <- db["renv", ] - if (identical(entry$Version, version)) { - message("* Installing renv ", version, " ... ", appendLF = FALSE) - dir.create(libpath, showWarnings = FALSE, recursive = TRUE) - utils::install.packages("renv", lib = libpath, quiet = TRUE) - message("Done!") - return(TRUE) - } - } - - # try to download renv - message("* Downloading renv ", version, " ... ", appendLF = FALSE) - prefix <- "https://api.github.com" - url <- file.path(prefix, "repos/rstudio/renv/tarball", version) - destfile <- tempfile("renv-", fileext = ".tar.gz") - on.exit(unlink(destfile), add = TRUE) - utils::download.file(url, destfile = destfile, mode = "wb", quiet = TRUE) - message("Done!") - - # attempt to install it into project library - message("* Installing renv ", version, " ... ", appendLF = FALSE) - dir.create(libpath, showWarnings = FALSE, recursive = TRUE) - - # invoke using system2 so we can capture and report output - bin <- R.home("bin") - exe <- if (Sys.info()[["sysname"]] == "Windows") "R.exe" else "R" - r <- file.path(bin, exe) - args <- c("--vanilla", "CMD", "INSTALL", "-l", shQuote(libpath), shQuote(destfile)) - output <- system2(r, args, stdout = TRUE, stderr = TRUE) - message("Done!") - - # check for successful install - status <- attr(output, "status") - if (is.numeric(status) && !identical(status, 0L)) { - text <- c("Error installing renv", "=====================", output) - writeLines(text, con = stderr()) - } - - - } - - try(install_renv()) - - # try again to load - if (requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) { - message("Successfully installed and loaded renv ", version, ".") - return(renv::load()) - } - - # failed to download or load renv; warn the user - msg <- c( - "Failed to find an renv installation: the project will not be loaded.", - "Use `renv::activate()` to re-initialize the project." - ) - - warning(paste(msg, collapse = "\n"), call. = FALSE) - -}) + +local({ + + # the requested version of renv + version <- "0.9.3" + + # avoid recursion + if (!is.na(Sys.getenv("RENV_R_INITIALIZING", unset = NA))) + return(invisible(TRUE)) + + # signal that we're loading renv during R startup + Sys.setenv("RENV_R_INITIALIZING" = "true") + on.exit(Sys.unsetenv("RENV_R_INITIALIZING"), add = TRUE) + + # signal that we've consented to use renv + options(renv.consent = TRUE) + + # load the 'utils' package eagerly -- this ensures that renv shims, which + # mask 'utils' packages, will come first on the search path + library(utils, lib.loc = .Library) + + # check to see if renv has already been loaded + if ("renv" %in% loadedNamespaces()) { + + # if renv has already been loaded, and it's the requested version of renv, + # nothing to do + spec <- .getNamespaceInfo(.getNamespace("renv"), "spec") + if (identical(spec[["version"]], version)) + return(invisible(TRUE)) + + # otherwise, unload and attempt to load the correct version of renv + unloadNamespace("renv") + + } + + # construct path to renv in library + libpath <- local({ + + root <- Sys.getenv("RENV_PATHS_LIBRARY", unset = "renv/library") + prefix <- paste("R", getRversion()[1, 1:2], sep = "-") + + # include SVN revision for development versions of R + # (to avoid sharing platform-specific artefacts with released versions of R) + devel <- + identical(R.version[["status"]], "Under development (unstable)") || + identical(R.version[["nickname"]], "Unsuffered Consequences") + + if (devel) + prefix <- paste(prefix, R.version[["svn rev"]], sep = "-r") + + file.path(root, prefix, R.version$platform) + + }) + + # try to load renv from the project library + if (requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) { + + # warn if the version of renv loaded does not match + loadedversion <- utils::packageDescription("renv", fields = "Version") + if (version != loadedversion) { + + # assume four-component versions are from GitHub; three-component + # versions are from CRAN + components <- strsplit(loadedversion, "[.-]")[[1]] + remote <- if (length(components) == 4L) + paste("rstudio/renv", loadedversion, sep = "@") + else + paste("renv", loadedversion, sep = "@") + + fmt <- paste( + "renv %1$s was loaded from project library, but renv %2$s is recorded in lockfile.", + "Use `renv::record(\"%3$s\")` to record this version in the lockfile.", + "Use `renv::restore(packages = \"renv\")` to install renv %2$s into the project library.", + sep = "\n" + ) + + msg <- sprintf(fmt, loadedversion, version, remote) + warning(msg, call. = FALSE) + + } + + # load the project + return(renv::load()) + + } + + # failed to find renv locally; we'll try to install from GitHub. + # first, set up download options as appropriate (try to use GITHUB_PAT) + install_renv <- function() { + + message("Failed to find installation of renv -- attempting to bootstrap...") + + # ensure .Rprofile doesn't get executed + rpu <- Sys.getenv("R_PROFILE_USER", unset = NA) + Sys.setenv(R_PROFILE_USER = "") + on.exit({ + if (is.na(rpu)) + Sys.unsetenv("R_PROFILE_USER") + else + Sys.setenv(R_PROFILE_USER = rpu) + }, add = TRUE) + + # prepare download options + pat <- Sys.getenv("GITHUB_PAT") + if (nzchar(Sys.which("curl")) && nzchar(pat)) { + fmt <- "--location --fail --header \"Authorization: token %s\"" + extra <- sprintf(fmt, pat) + saved <- options("download.file.method", "download.file.extra") + options(download.file.method = "curl", download.file.extra = extra) + on.exit(do.call(base::options, saved), add = TRUE) + } else if (nzchar(Sys.which("wget")) && nzchar(pat)) { + fmt <- "--header=\"Authorization: token %s\"" + extra <- sprintf(fmt, pat) + saved <- options("download.file.method", "download.file.extra") + options(download.file.method = "wget", download.file.extra = extra) + on.exit(do.call(base::options, saved), add = TRUE) + } + + # fix up repos + repos <- getOption("repos") + on.exit(options(repos = repos), add = TRUE) + repos[repos == "@CRAN@"] <- "https://cloud.r-project.org" + options(repos = repos) + + # check for renv on CRAN matching this version + db <- as.data.frame(available.packages(), stringsAsFactors = FALSE) + if ("renv" %in% rownames(db)) { + entry <- db["renv", ] + if (identical(entry$Version, version)) { + message("* Installing renv ", version, " ... ", appendLF = FALSE) + dir.create(libpath, showWarnings = FALSE, recursive = TRUE) + utils::install.packages("renv", lib = libpath, quiet = TRUE) + message("Done!") + return(TRUE) + } + } + + # try to download renv + message("* Downloading renv ", version, " ... ", appendLF = FALSE) + prefix <- "https://api.github.com" + url <- file.path(prefix, "repos/rstudio/renv/tarball", version) + destfile <- tempfile("renv-", fileext = ".tar.gz") + on.exit(unlink(destfile), add = TRUE) + utils::download.file(url, destfile = destfile, mode = "wb", quiet = TRUE) + message("Done!") + + # attempt to install it into project library + message("* Installing renv ", version, " ... ", appendLF = FALSE) + dir.create(libpath, showWarnings = FALSE, recursive = TRUE) + + # invoke using system2 so we can capture and report output + bin <- R.home("bin") + exe <- if (Sys.info()[["sysname"]] == "Windows") "R.exe" else "R" + r <- file.path(bin, exe) + args <- c("--vanilla", "CMD", "INSTALL", "-l", shQuote(libpath), shQuote(destfile)) + output <- system2(r, args, stdout = TRUE, stderr = TRUE) + message("Done!") + + # check for successful install + status <- attr(output, "status") + if (is.numeric(status) && !identical(status, 0L)) { + text <- c("Error installing renv", "=====================", output) + writeLines(text, con = stderr()) + } + + + } + + try(install_renv()) + + # try again to load + if (requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) { + message("Successfully installed and loaded renv ", version, ".") + return(renv::load()) + } + + # failed to download or load renv; warn the user + msg <- c( + "Failed to find an renv installation: the project will not be loaded.", + "Use `renv::activate()` to re-initialize the project." + ) + + warning(paste(msg, collapse = "\n"), call. = FALSE) + +})