谁能帮我找出我在这段代码中的错误在哪里?这就是我得到的:“错误:“}”中的意外'}'”
如果我尝试只运行循环下的块,一切都很好,但我需要在 50 页中处理它,然后合并。
library(pdftools)
library(tidyr)
library(sqldf)
sDirectorio = "/Users/muribe/Desktop"
archivoPDF = pdftools::pdf_text(file.path(sDirectorio,"centros_votacion.pdf"))
n = 0
WHILE (n <8) {
n=n+1
vLineas = unlist( strsplit(archivoPDF[n], split = c("\r\n")) )
dfDefinicionTabla = data.frame( Orden = 1:9,
Campo = c("Codigo","Provincia","Canton","Distrito","JRVInicial","JRVFinal","TotalJRV","TipoCentro","CentroVotacion"),
Inicio = c(1,8,21,36,75,86,97,104,127),
Fin = c(7,20,35,74,85,96,103,126,180),
Tipo = c("numeric","character","character","character","numeric","numeric","numeric","character","character"),
stringsAsFactors = FALSE)
dfTabla = data.frame()
for (linea in 7:length(vLineas)) {
dfFila = data.frame(n, stringsAsFactors = FALSE)
for (campo in 1:nrow(dfDefinicionTabla)){
# campo = 2
# Extrae cada uno de los campos de la linea
dfFila =cbind(dfFila, trimws(substr( vLineas[linea],
dfDefinicionTabla[campo,]$Inicio,
dfDefinicionTabla[campo,]$Fin),
which = "both")
)
}
colnames(dfFila)[2:(nrow(dfDefinicionTabla)+1)] = dfDefinicionTabla$Campo
dfTabla <- rbind(dfTabla, dfFila)
}
}
print(dfTabla)``