Skip to content

Commit

Permalink
cleanup function now only deletes the extracted directory
Browse files Browse the repository at this point in the history
  • Loading branch information
hmeleiro committed May 30, 2024
1 parent 4aaecd4 commit bd1b3fa
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion R/candidatos_nosenado.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ candidatos_nosenado <- function(tipo, anno, mes) {
df$nacimiento <- NA
df$dni <- NA

cleanup(temp, tempd)
cleanup(tempd)

return(df)
}
4 changes: 1 addition & 3 deletions R/cleanup.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#' @title Cleans up the files and directories created during the process
#'
#' @param files The files to remove.
#' @param dirs The directories to remove.
#'
#' @return NULL
#'
#' @keywords internal
#'
cleanup <- function(files, dirs) {
# file.remove(files)
cleanup <- function(dirs) {
unlink(dirs, recursive=TRUE)
}
9 changes: 5 additions & 4 deletions R/download_bin.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ download_bin <- function(url, tempfile) {
"Gecko/20100101 Firefox/98.0"
)

if(file.exists(tempfile)) {
message("File already exists, skipping download")
if (file.exists(tempfile)) {
message(
"File already exists, skipping download. Reading existing file ",
gsub("..+/", "", tempfile)
)
} else {
message("Downloading ", url)
res <- GET(url, add_headers(`User-Agent` = UA, Connection = "keep-alive"))
writeBin(res$content, tempfile)
}


}
2 changes: 1 addition & 1 deletion R/mesas.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ mesas <- function(tipo_eleccion, anno, mes) {

df$municipio[df$codigo_municipio == "999"] <- "CERA"

cleanup(temp, tempd)
cleanup(tempd)

return(df)
}
2 changes: 1 addition & 1 deletion R/muni.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ municipios <- function(tipo_eleccion, anno, mes, distritos = FALSE) {
df <- unique(df[df$codigo_distrito == 99, ])
}

cleanup(temp, tempd)
cleanup(tempd)

return(df)
}
2 changes: 1 addition & 1 deletion R/provincias.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ provincias <- function(tipo_eleccion, anno, mes) {
desc("votos")
)

cleanup(temp, tempd)
cleanup(tempd)

return(df)
}
2 changes: 1 addition & 1 deletion R/senado_mesas.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ senado_mesas <- function(anno, mes) {

df$nacimiento[df$nacimiento_anno == "0000"] <- NA

cleanup(temp, tempd)
cleanup(tempd)

return(df)
}
2 changes: 1 addition & 1 deletion R/senado_municipios.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ senado_municipios <- function(anno, mes) {

df$nacimiento[df$nacimiento_anno == "0000"] <- NA

cleanup(temp, tempd)
cleanup(tempd)

return(df)
}
4 changes: 1 addition & 3 deletions man/cleanup.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bd1b3fa

Please sign in to comment.