Bueno os dejo para que veais como va la cosa. Gracias por el feedback *Shell de linux*
Los shells de Linux son superútiles para limpiar grandes bases de datos. En Linux y mac los tenemos en Windows. Para utilizar estos sctripts en Windows lo ideal es 1.- Instalar cygwin # https://www.cygwin.com/ 2 Añadirlo al PATH de DOS. Doblecheckear que porque es un poco cabezón # Añadir al path ir a mi pc -> propiedades -> Advanced -> Environment variables # En la variable PATH añadimos "C:\Cygwin\bin" para poder llamará a las órdenes de cygwyn # http://stackoverflow.com/questions/20315824/how-to-call-cygwin-command-from-r 3.-Runear la ordenes en consolar normal. En R dan problemas las pipes. No tengo ni idea porque. Porque funcionan en DOS y cygwin Los espacios van fatal a la hora de meter rutas los ficheros sh funcionan en cygwin pero no funcinan en R Algunos ejemplos ========================================================== Sustituvo malo de la pipe ========================================================== Las ordenes simples funcionan. setwd(dir = "C:/Users/Javier Villacampa/Desktop/") x <- system("tail -n 30 hola.txt", intern = T) write.table(x = x,file = "output.csv",sep = "@",row.names = F, col.names = F,quote = F) read.csv(file = "output.csv",header = F,sep = "@") x <- system("head -n 10 output.csv", intern = T) unlink("output.csv") ========================================================== Esto fueron los primeros intentos ========================================================== system('wc -l hola.csv') # Con la orden ya metida en el path system('C:/cygwin/bin/wc -l hola.csv') # Sin ella ========================================================== Llamar a consola y utilizar sh (puedo mirar mis commandos de fast-dm para el problema de los espacions) ========================================================== # http://357mkr.blogspot.com.es/2011/01/reparar-diccionarios-formato-dos-unix.html # Los ficheros sh han de estar en notepad # http://357mkr.blogspot.com.es/2011/01/reparar-diccionarios-formato-dos-unix.html Fichero foo.sh ############## #!/bin/sh tail -n 5 hola.csv echo "=======================" head -n 5 hola.csv echo "=======================@" head -n 10 Hola.csv | tail ############## system('cmd.exe /c c:\\cygwin\\bin\\sh /cygdrive/c/Users/Javier\ Villacampa/Desktop/foo.sh', TRUE) # Curiosamente este ejemplo funciona en cygwyn. # En consola cygwin # Pero deja de funcionar en consola DOS a pesar de que la ordenes corren copiando y pegand # El mismo error me encuetro en R agravado a que aquí las pipes no me funcionan. ========================================================== Awk por investigar ========================================================== # http://gnuwin32.sourceforge.net/packages/gawk.htm # http://www.inside-r.org/packages/cran/Kmisc # Los ficheros awk llevan otra lógica e imagino que hay que desarrollarlo por otro lado. Puede ser de ayuda la librería Kmisc system("awk \'{gsub( \"M.?G\",\"MEG\"); print}\' hola, intern = T) x <- system("C:/cygwin/bin/awk \'{gsub( \"M.?G\",\"MEG\"); print}\' hola.csv", intern = T) =============================================================================== ERRORES en sh =============================================================================== ############################################3 # Error Sh consola Windows. Funciona si no essh ############################################ # C:\Users\Javier Villacampa\Desktop>sh foo4.sh # ?#!/bin/sh: not found # 1 [main] tail (41276) C:\cygwin\bin\tail.exe: *** fatal error - cygheap ba # se mismatch detected - 0x612A1970/0x612E1400. # This problem is probably due to using incompatible versions of the cygwin DLL. # Search for cygwin1.dll using the Windows Start->Find/Search facility # and delete all but the most recent version. The most recent version *should* # reside in x:\cygwin\bin, where 'x' is the drive on which you have # installed the cygwin distribution. Rebooting is also suggested if you # are unable to find another cygwin DLL. # ======================= # # 752923199;2;00-AH-71;15768;1;1;1;22037;1;1;1 # 753040251;1;02-08-BC;0;0;0;1;0;0;0;0 # 753071415;1;06-06-TB;0;0;0;1;0;0;0;1 # 753030262;1;06-26-AO;0;0;0;0;0;0;0;0 # =======================@ # 2 [main] tail (65356) C:\cygwin\bin\tail.exe: *** fatal error - cygheap ba # se mismatch detected - 0x612A1970/0x612E1400. # This problem is probably due to using incompatible versions of the cygwin DLL. # Search for cygwin1.dll using the Windows Start->Find/Search facility # and delete all but the most recent version. The most recent version *should* # reside in x:\cygwin\bin, where 'x' is the drive on which you have # installed the cygwin distribution. Rebooting is also suggested if you # are unable to find another cygwin DLL. ############################################3 # Error Sh consola R. ############################################ # # [1] "foo4.sh: line 1: #!/bin/sh: No such file or directory" # [2] "753003840;1;26-MO-54;42000;1;1;1;41944;1;1;1" # [3] "753218504;2;2963 BFT;0;0;0;1;0;0;0;1" # [4] "751885448;11;82-17-UT;0;0;1;1;5104;0;1;1" # [5] "753053463;3;11-81-JP;0;0;0;1;0;0;0;1" # [6] "753053463;2;19-75-RB;0;0;0;1;0;0;0;1" # [7] "=======================" # [8] " 1 [main] head (32500) C:\\Rtools\\bin\\head.exe: *** fatal error - cygheap base mismatch detected - 0x612E1400/0x612A1970." # [9] "This problem is probably due to using incompatible versions of the cygwin DLL." # [10] "Search for cygwin1.dll using the Windows Start->Find/Search facility" # [11] "and delete all but the most recent version. The most recent version *should*" # [12] "reside in x:\\cygwin\\bin, where 'x' is the drive on which you have" # [13] "installed the cygwin distribution. Rebooting is also suggested if you" # [14] "are unable to find another cygwin DLL." # [15] "=======================@" # [16] " 4 [main] head (7308) C:\\Rtools\\bin\\head.exe: *** fatal error - cygheap base mismatch detected - 0x612E1400/0x612A1970." # [17] "This problem is probably due to using incompatible versions of the cygwin DLL." # [18] "Search for cygwin1.dll using the Windows Start->Find/Search facility" # [19] "and delete all but the most recent version. The most recent version *should*" # [20] "reside in x:\\cygwin\\bin, where 'x' is the drive on which you have" # [21] "installed the cygwin distribution. Rebooting is also suggested if you" # [22] "are unable to find another cygwin DLL." El 8 de junio de 2015, 21:32, <[email protected]> escribió: > Estimado Javier Villacampa González > > Hace mucho que no uso awk o gawk, pero recuerdo cygwin y en lo personal no > tuve inconvenientes con awk. > > No se como está esa tecnología hoy en día, pero yo evalué usar R con awk, > al respecto hay una integración en > http://www.inside-r.org/packages/cran/Kmisc/docs/awk > > Javier Rubén Marcuzzi > Técnico en Industrias Lácteas > Veterinario > > *De:* Javier Villacampa González <[email protected]> > *Enviado el:* lunes, 08 de junio de 2015 03:05 p.m. > *Para:* Carlos Ortega <[email protected]> > *CC:* [email protected] <[email protected]> > > Al final resulto más fácil de lo esperado. Hay que instalar cywin y > utilizar los comandos de la siguiente manera > > system('C:/cygwin/bin/wc -l var_risco_2012.csv') > Esto en principio funciona > > El 8 de junio de 2015, 17:41, Carlos Ortega <[email protected]> > escribió: > > > Hola, > > > > Mira esto: > > > > http://stackoverflow.com/questions/18603984/using-system-with-windows > > > > Saludos, > > Carlos Ortega > > www.qualityexcellence.es > > > > El 8 de junio de 2015, 17:14, Javier Villacampa González < > > [email protected]> escribió: > > > >> Hola buenas, > >> > >> a veces empleo desde R shells de unix, Existe alguna manera de utilizar > >> estos shelss desde windows o el lenguaje awk. > >> > >> La idea es hacerlo siempre desde R, igual invoncando cygwin desde > windows > >> es posible. Pero no me queda claro > >> > >> Un abrazo y gracias por adelntado > >> > >> Javier > >> #_____________________________________________________________________ > >> # EJEMPLO, ¿Que habría que poner en > >> # ¿¿¿¿¿¿??????????????? > >> # suponiendoq que tengo cygwin instalado > >> #_____________________________________________________________________ > >> > >> # Un ejemplo sería cambiar unos MËG por unos MEG ya que fread no me lee > >> bien los Ë > >> > >> file.rename(from = "Data/data.csv", to = "Data/data_2.csv") > >> switch(OS, > >> WIN = system( ¿¿¿¿¿¿???????????????), > >> MAC = system( command = "awk \'{gsub( \"M.?G\",\"MEG\"); > print}\' > >> Data/data_2.csv" > Data/data_2_2.csv"") > >> ) > >> file.rename(from = "Data/data.csv", to = "Data/data_2.csv") > >> > >> -- > >> > >> [[alternative HTML version deleted]] > >> > >> _______________________________________________ > >> R-help-es mailing list > >> [email protected] > >> https://stat.ethz.ch/mailman/listinfo/r-help-es > >> > > > > > > > > -- > > Saludos, > > Carlos Ortega > > www.qualityexcellence.es > > > > > > -- > > [[alternative HTML version deleted]] > > _______________________________________________ > R-help-es mailing list > [email protected] > https://stat.ethz.ch/mailman/listinfo/r-help-es > -- [[alternative HTML version deleted]] _______________________________________________ R-help-es mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-help-es
