utilFinalAccountabilityCsvToDataFrame <- function(year,
datafolder,
filePattern,
federativeBody,
layoutType,
csvLayouts,
toFile = T){
message("Processing the data...")
orig <- getwd()
setwd(dataFolder)
#setAs("character","br.date", function(from) as.Date(from, format="%d/%m/%Y") )
dfData <- Sys.glob(sprintf(filePattern, year, body)) %>%
lapply(read.table,
colClasses = "character", # --> isso não deu certo: layouts$receitas_de_candidatos$Type
header = T,
sep = ";",
na.strings = "#NULO",
stringsAsFactors = F,
fill = T,
fileEncoding = 'windows-1252') %>%
dplyr::bind_rows()
dataLayout <- eval(parse(text = paste0("layouts$", layoutType)))
#for(i in which(layouts$receitas_de_candidatos$Type=="numeric")) {
for(i in which(dataLayout$Type == "numeric")) {
dfData[,i] <- as.numeric(dfData[,i])
}
for(i in which(dataLayout$Type == "br.date")) {
dfData[,i] <- as.Date(dfData[,i], format="%d/%m/%Y")
}
dfData$Ano.eleicao <- year
setwd(orig)
if (toFile){
fileName <- paste0(paste(layoutType, year, sep = "_"), ".RDS")
saveRDS(dfData, file = fileName)
dfData <- data.frame(
fileName = fileName,
stringsAsFactors = F)
}
dfData
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.