[R-es] leer ficheros excel en R en Ubuntu

Miguel Fiandor Gutiérrez miguel.fiandor.gutierrez en gmail.com
Vie Ago 15 17:54:45 CEST 2014


@daniel, sí ya lo instalé, y con eso pude ejecutar otros paquetes.

Pero el fichero xls que tengo es un poco especial, y por dentro es html
puro, una tabla directamente. Así que lo he abierto con la librería XML ,
pero me lo abre como una lista. Quería pasarlo a dataframe y luego
exportarlo a csv para asegurarme de que cargaba los datos bien.

->

library(XML)
table <- readHTMLTable("madrid.xls")
library (plyr)
df <- ldply (table, data.frame)
df
write.csv2(file="output_madrid.csv", x=df)


Gracias por la ayuda!



El 15 de agosto de 2014, 16:20, daniel <daniel319 en gmail.com> escribió:

> Miguel,
>
> Me parece que el problema esta en rJava, intenta:
>
> sudo apt-get install r-cran-rJava
>
> Si te da error dinos que dice.
>
> Suerte,
>
> Daniel
>
>
>
>
> El 15 de agosto de 2014, 10:46, "Marcuzzi, Javier Rubén" <
> javier.ruben.marcuzzi en gmail.com> escribió:
>
> > Estimado Miguel
> >
> > Entiendo su postura, una ayuda es desde el paquete Rcmdr, datos,
> importar,
> > seleccionar el archivo xls y se escribe todo solo, lueogo puede copiar y
> > pegar la parte del código relacionado a la importación, a un archivo R y
> > listo, pero ..., creo que solo funciona correctamente en windows (tendría
> > que intentarlo a la fecha de hoy).
> >
> > Javier Marcuzzi
> >
> >
> > El 15/08/2014 04:29 a.m., Miguel Fiandor Gutiérrez escribió:
> >
> >> Hola,
> >>
> >> @javier, me gustaría no tener que hacer nada de forma manual, ni por
> fuera
> >> de r, rstudio. Es decir, el típico comando de linux que me convierta de
> >> xls
> >> a csv prefiero no usarlo. Me gustaría hacerlo todo desde R.
> >>
> >> @jorge ->
> >>
> >> Con RODBC me salta ->
> >>
> >> Error: could not find function "odbcConnectExcel"
> >>
> >> Lo que creo que es inevitable en Ubuntu
> >> <http://stackoverflow.com/questions/3426523/odbcconnectexcel-function-
> >> from-rodbc-package-for-r-not-found-on-ubuntu>
> >> Con gdata ->
> >>
> >> Unable to open file
> >> '/home/miguelfg/R/x86_64-pc-linux-gnu-library/3.1/gdata/
> >> xls/madrid.xls'.Error
> >> in xls2sep(xls, sheet, verbose = verbose, ..., method = method,  :
> >>    Intermediate file '/tmp/RtmpHRuknw/filefed757fcc67.csv' missing!In
> >> addition: Warning message:running command ''/usr/bin/perl'
> >>
> >> Con XLConnect ->
> >>
> >> Error : package ‘rJava’ was built before R 3.0.0: please re-install
> >> itERROR: lazy loading failed for package ‘XLConnectJars’* removing
> >> ‘/home/miguelfg/R/x86_64-pc-linux-gnu-library/3.1/XLConnectJars’Warning
> >> in install.packages :
> >>    installation of package ‘XLConnectJars’ had non-zero exit
> >> statusERROR: dependency ‘XLConnectJars’ is not available for package
> >> ‘XLConnect’* removing
> >> ‘/home/miguelfg/R/x86_64-pc-linux-gnu-library/3.1/XLConnect’Warning in
> >> install.packages :
> >>    installation of package ‘XLConnect’ had non-zero exit status
> >>
> >> Con xlsReadWrite -> me dice que no está disponible para R 3.1.1 Con xlsx
> >> ->
> >>
> >> Error : package ‘rJava’ was built before R 3.0.0: please re-install
> >> itERROR: lazy loading failed for package ‘xlsxjars’* removing
> >> ‘/home/miguelfg/R/x86_64-pc-linux-gnu-library/3.1/xlsxjars’Warning in
> >> install.packages :
> >>    installation of package ‘xlsxjars’ had non-zero exit statusERROR:
> >> dependency ‘xlsxjars’ is not available for package ‘xlsx’* removing
> >> ‘/home/miguelfg/R/x86_64-pc-linux-gnu-library/3.1/xlsx’Warning in
> >> install.packages :
> >>    installation of package ‘xlsx’ had non-zero exit status
> >>
> >> ================================= Viendo que el problema parecía java +
> >> rJava, busqué y ejecuté -> sudo R CMD javareconf -e Pero parece que no
> >> termina bien -> conftest.c:1:17: fatal error: jni.h: No such file or
> >> directory compilation terminated. make: *** [conftest.o] Error 1 Unable
> to
> >> compile a JNI program
> >>
> >>
> >> El 15 de agosto de 2014, 2:23, Jorge I Velez <jorgeivanvelez en gmail.com>
> >> escribió:
> >>
> >>  Hola Miguel,
> >>>
> >>> A que te refieres con "y nada"?  Obtienes algun error?  Algun mensaje?
> >>>   Has probado con scan() y/o readLines()?
> >>>
> >>> Saludos,
> >>> Jorge.-
> >>>
> >>>
> >>>
> >>> 2014-08-15 7:38 GMT+10:00 Miguel Fiandor Gutiérrez <
> >>> miguel.fiandor.gutierrez en gmail.com>:
> >>>
> >>>  Hola,
> >>>>
> >>>> Pensé que esto iba a ser trivial en R, pero me estoy encontrado muchos
> >>>> con
> >>>> mi problema en internet, y que las soluciones ofrecidas no terminan de
> >>>> funcionar.
> >>>>
> >>>> Estoy intentando leer un fichero .xls en ubuntu con los siguientes
> >>>> paquetes
> >>>> y nada:
> >>>>
> >>>> require(RODBC)
> >>>> conn = odbcConnectExcel("madrid.xls") # open a connection to the Excel
> >>>> file
> >>>> sqlTables(conn)$TABLE_NAME # show all sheets
> >>>> df = sqlFetch(conn, "Sheet1") # read a sheet
> >>>> df = sqlQuery(conn, "select * from [Sheet1 $]") # read a sheet
> >>>> (alternative
> >>>> SQL sintax)
> >>>> close(conn) # close the connection to the file
> >>>>
> >>>> require(gdata)
> >>>> xlsfile <- file.path(path.package('gdata'),'xls','madrid.xls')
> >>>> df = read.xls (xlsfile)
> >>>> df = read.xls (xlsfile, sheet = 1, header = TRUE)
> >>>> df = read.xls ("madrid.xls", sheet = 1, header = TRUE)
> >>>> df = read.xls ("madrid.xls")
> >>>>
> >>>> require(xlsx)
> >>>> read.xlsx("madrid.xls", sheetName = "Sheet1")
> >>>>
> >>>> library(XLConnect)
> >>>> wk = loadWorkbook("madrid.xls")
> >>>> df = readWorksheet(wk, sheet="Sheet1")
> >>>>
> >>>> --
> >>>>
> >>>> también he probado directamente read.table ya que el fichero es tipo
> xml
> >>>> por dentro:
> >>>> df = read.table("madrid.xls", header = TRUE)
> >>>>
> >>>>
> >>>> -- ejemplo del fichero:
> >>>> $ head -c 500 madrid.xls
> >>>> <table border="1"><tr><th bgcolor="#FFB18C">Nombre de la
> >>>> instalacion</th><th bgcolor="#FFB18C">Municipio de la
> >>>> instalacion</th><th
> >>>> bgcolor="#FFB18C">Provincia de la instalacion</th><th
> >>>> bgcolor="#FFB18C">Clave del registro</th><th bgcolor="#FFB18C">Codigo
> >>>> registro autonomico definitivo</th><th bgcolor="#FFB18C">Potencia
> >>>> nominal
> >>>> de la fase (kW)</th><th bgcolor="#FFB18C">Grupo Normativo</th><th
> >>>> bgcolor="#FFB18C">Tipo de Inscripcion</th></tr><tr><td>PERGOLA
> >>>> FOTOVOLTAICA
> >>>> JARDINES COMPLEJO DE MONCLOA
> >>>> ...
> >>>>
> >>>>
> >>>> Gracias de antemano.
> >>>>
> >>>> Por cierto, aprovecho que lanzo la pregunta es para una aplicación
> >>>> Shiny,
> >>>> alguna recomendación de como leer esta info solo una vez al arrancar
> el
> >>>> servidor?
> >>>>
> >>>>
> >>>> Miguel
> >>>>
> >>>>          [[alternative HTML version deleted]]
> >>>>
> >>>> _______________________________________________
> >>>> R-help-es mailing list
> >>>> R-help-es en r-project.org
> >>>> https://stat.ethz.ch/mailman/listinfo/r-help-es
> >>>>
> >>>>
> >>>          [[alternative HTML version deleted]]
> >>
> >> _______________________________________________
> >> R-help-es mailing list
> >> R-help-es en r-project.org
> >> https://stat.ethz.ch/mailman/listinfo/r-help-es
> >>
> >
> > _______________________________________________
> > R-help-es mailing list
> > R-help-es en r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-help-es
> >
>
>
>
> --
> Daniel
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-help-es mailing list
> R-help-es en r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>

	[[alternative HTML version deleted]]



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