[R-es] Consulta

Carlos Ortega co| @end|ng |rom qu@||tyexce||ence@e@
Mar Sep 24 09:09:07 CEST 2019


Hola,

Una cosa que puedes hacer temporalmente es desinstalar la versión 3.6.1 y
volver a  la anterior 3.6.0.
Los paquetes tardan un tiempo, suele ser poco, en adaptarse a las nuevas
versiones.

Pero vaya, en cualquier caso, 3.6.1 ya lleva un tiempo liberada y esta
adaptación se debiera de haber producido.
Si nos das más detalles del error que tienes y en qué paso de tu script
aparece el error, podríamos ayudarte más.

Gracias,
Carlos Ortega
www.qualityexcellence.es

El mar., 24 sept. 2019 a las 1:49, BERENICE DOMINGUEZ SANCHEZ (<
ds_bere using hotmail.com>) escribió:

> Buenas tarde a todo using s:
>
> Tenia la versión de R 3.6 y utilizaba la paquetería de pdftools para
> extraer información de archivos en pdf actualice la versión 3.6.1 y ya no
> reconoce la paquetería alguien que me pueda ayudar. Prácticamente no
> reconoce las funciones de pdftools
>
> library(pdftools)
> library(stringr)​
> library(NLP)​
> library(tm)​
> library(tesseract)​
> library(magick)​
> install.packages("magick")​
> install.packages("pdftools")​
>> txt <- system.file("texts", "txt", package = "tm")​
>> rfc_rg <- "([A-Z]{3,})([0-9]{6})([A-Z]|[0-9]){0,3}"​
> #poliza_rg <-
> "(34|36|37|39)(ME|MEC|CH|MB|TF|GI|VE|TS|IM|ER|VE)*([0-9]{6,})[-]([0-9]){2}[-][A-Z]"​
> poliza_rg <- "(ME|CH|MB|TF|GI|gi|VE|TS|IM|ER|VE)*([0-9]{8,})[-]([0-9]){2}"​
> registro_rg <- "(CNSF-H0711-)([0-9]{4})[- ]([0-9]){4}"​
> subgrupo_rg <- "_([0-9]){1,3}."​
> mon_rg <- "SMGM|UMAM|MN"​
>>> ruta <- 'C:/Users/bdominguez/Documents/H0711/Bond/1909/'​
> archivos<-list.files(path=ruta,pattern = '*.pdf')​
>>> imagen <- image_read_pdf(path=paste(ruta,"/",nombre,".pdf",sep=""))​
> prueba <-image_ocr(imagen, language = 'eng')​
> lineas<-unlist(str_split(prueba,pattern = "\n"))​
> lineasp<-unlist(str_split(prueba[2],pattern = "\r\n"))​
>> newnom <- NULL​
> renglones <- NULL​
> for (nombre in archivos){​
>   subgrupo <- str_extract(str_extract(nombre,pattern =
> subgrupo_rg),pattern = "[0-9]{1,3}")​
>   imagen <- image_read_pdf(path=paste(ruta,"/",nombre,".pdf",sep=""))​
>   prueba <-image_ocr(imagen, language = 'eng')​
>   lineas<-unlist(str_split(prueba,pattern = "\n"))​
>   poliza <- NULL​
>   poliza<-str_extract(lineas[1],poliza_rg)​
>   newnom <- c(newnom,paste(poliza[1],substr(nombre,5,6),".pdf",sep=''))​
>>   registro <- NULL​
>   registro<-str_extract(lineas[49],registro_rg)​
>>   rfc <- NULL​
>   rfc <- str_extract(lineas[5],rfc_rg)​
>>>   #lineasnew<-unlist(str_split(lineas[2],pattern = "\r\n"))​
>   #lineasdosnew<-unlist(str_split(lineas[1],pattern = "\r\n"))​
>>   cobertura <- NA​
>   extranjera <- NA​
>   suma_str   <- NA​
>   deducible_str <- NA​
>>   suma <- NA​
>   coaseguro <- NA​
>   deducible <- NA​
>   tope <- NA​
>   mon <- NA​
>   mondedu <- NA​
>>   cobertura  <- grep("Cobertura en el Extranjero",lineas,value=TRUE)​
>   extranjera <- grep("Emergencia en el Extranjero",lineas,value=TRUE)​
>   suma_str   <- grep("SUMA ASEGURADA:",lineas,value=TRUE)​
>   deducible_str   <- grep("DEDUCIBLE:",lineas,value=TRUE)​
>   sumacob <- NA​
>   sumaext <- NA​
>>   pprimaria <- grep("Numero de Póliza:", lineas, value = TRUE)​
>   dnprimariaa <- grep("Nombre de la Aseguradora Primaria:", lineas, value
> = TRUE)​
>>   #cer<- grep("Certificado No. ",lineas, value=TRUE)​
>   #ntit<- grep("Ramo", lineas, value=TRUE)​
>>   sumacob<-as.numeric(str_extract(cobertura[1],pattern = "[0-9]{1,}"))​
>   if (length(sumacob)==0){​
>     sumacob = NA​
>   }​
>>   sumaext<-as.numeric(str_extract(extranjera[17],pattern = "[0-9]{1,}"))​
>   if (length(sumaext)==0){​
>     sumaext = NA​
>   }​
>   valores <- NULL​
>   monedas <- NULL​
>   valores <- str_extract_all(suma_str[17],pattern =
> "[0-9]{0,3},*[0-9]{0,3},*[0-9]{1,3}(.[0-9]{1,}){0,1}",simplify=TRUE)​
>   monedas <- str_extract(suma_str,pattern = mon_rg)​
>   if (length(valores[1])==0){​
>     suma = NA​
>     mon = NA​
>   }else{​
>     suma = as.numeric(gsub(pattern = ",*",replacement = "",valores[1]))​
>     mon <- as.character(monedas[1])​
>   }​
>>   if (length(valores[2])==0){​
>     coaseguro = NA​
>   }else{​
>     coaseguro = as.numeric(valores[2])​
>   }​
>   valores <- NULL​
>   valores <- str_extract_all(deducible_str[1],pattern =
> "[0-9]{0,3},*[0-9]{0,3},*[0-9]{1,3}(.[0-9]{1,}){0,1}",simplify=TRUE)​
>>   if (length(valores[1])==0){​
>     deducible <- NA​
>   }else{​
>     deducible <- as.numeric(gsub(pattern = ",",replacement =
> "",valores[1]))​
>   }​
>>   monedas <- NULL  ​
>   monedas <- str_extract(deducible_str[1],pattern = mon_rg)​
>>   if (length(monedas)==0){​
>     mondedu <- NA​
>   }else{​
>     mondedu <- monedas​
>   }​
>>>   if (length(valores[2])==0){​
>     tope = NA​
>   }else{​
>     tope = as.numeric(gsub(pattern = ",",replacement = "",valores[2]))​
>   }​
>>   renglon <-
> data.frame(archivo=nombre,poliza=as.character(poliza[1]),cobertura=sumacob,emergencia=sumaext,registro=registro[1],suma=suma,coaseguro=coaseguro,deducible=deducible,tope=tope,rfc=rfc,mon=mon,mondedu=mondedu,subgrupo=subgrupo,
> cert=as.character(cer[1]), cer_tit=as.character(lineasdos[14]),
> titu=as.character(lineasdos[10]))​
>   renglones <- rbind(renglones,renglon)​
> }​
>> # Con los datos del data frame renombra los archivos hay que crear los
> subdirectorios​
>> noms <- data.frame(archivo=archivos,poliza=newnom)​
>> noms <- renglones[!is.na(renglones$poliza),c('archivo','cer_tit')]​
> ungrupo<-sqldf("select poliza,count(cert) from noms group by 1  having
> count(cert) <= 1 ")​
> noms<-sqldf("select * from noms where poliza in (select poliza from
> ungrupo)")​
> length(noms$archivo)​
> salida <- "/renombra/"​
>> for (i in 1:length(noms[,1])){​
>   if (!is.na(noms[i,'cer_tit'])){​
>     pfrom <- paste(ruta,"/",noms[i,'archivo'],sep='')​
>     pto <- paste(ruta,salida,noms[i,'cer_tit'],'.pdf',sep='')​
>     if (!file.exists(pto)){​
>       file.copy(from = pfrom,to=pto)​
>     }​
>   }​
> }​
>> #Ahora las polizas con subgrupos​
> noms <- renglones[!is.na
> (renglones$poliza),c('archivo','poliza','subgrupo')]​
> ungrupo<-sqldf("select poliza,count(subgrupo) from noms group by 1  having
> count(subgrupo) > 1 ")​
> noms<-sqldf("select * from noms where poliza in (select poliza from
> ungrupo) order by poliza")​
> length(noms$archivo)​
> salida <- "/Renombra/ConGrupos/"​
>> for (i in 1:length(noms[,1])){​
>   if (!is.na(noms[i,'poliza'])){​
>     pfrom <- paste(ruta,"/",noms[i,'archivo'],sep='')​
>     pto <-
> paste(ruta,salida,noms[i,'poliza'],'_',noms[i,'subgrupo'],'.pdf',sep='')​
>     if (!file.exists(pto)){​
>       file.copy(from = pfrom,to=pto)​
>     }​
>   }​
> }​
>> salida <- "/Renombra/Grupos/"​
> dirActual <- getwd()​
> polizas_con_grupos <- as.character(sqldf("select poliza from
> ungrupo")$poliza)​
> setwd(ruta)​
> for (policita in polizas_con_grupos){​
>   archivos <- as.character(sqldf(paste("select archivo from renglones
> where poliza like '%",policita,"%'",sep=''))$archivo)​
>   staple_pdf(input_files = archivos,output_filepath =
> paste(ruta,salida,policita,".pdf",sep='')) ​
> }​
> setwd(dirActual)​
>> #Ahora los PDf sin poliza​
> noms <- renglones[is.na(renglones$poliza),c('archivo','poliza')]​
> salida <- "/renombra/SinPoliza/"​
> for (i in 1:length(noms[,1])){​
>   pfrom <- paste(ruta,"/",noms[i,'archivo'],sep='')​
>   pto <- paste(ruta,salida,noms[i,'archivo'],sep='')​
>   if (!file.exists(pto)){​
>     file.copy(from = pfrom,to=pto)​
>   }​
> }​
>> View(renglones)​
> write.csv(renglones, file='//
> 192.168.1.83/share/CERT/CERTIFICADOS_INDIVIDUALES_295_UMAM/Renombra/CERTIFICADOS_INDIVIDUALES_295_UMAM.csv')
>>>>>
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-help-es mailing list
> R-help-es using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>


-- 
Saludos,
Carlos Ortega
www.qualityexcellence.es

	[[alternative HTML version deleted]]



Más información sobre la lista de distribución R-help-es