mazibuko
2010-Jun-05 02:45 UTC
[R] Write.fwf works from Mac, throws different number of row error in Windows
Hello, I am having a problem with write.fwf in Windows. I wrote a code to ingest a number of text files with weather data in them, process them, and then output a text file with two parts: 1) a set of column names, 2) the processed data table. I wrote and tested the program on my Mac, and it worked fine. However, on the windows machine, where I intend the work to be done, when I run the following line (last line of the script):> write.fwf(outframe,file=outfile1,sep="",quote=FALSE,rownames=FALSE,colnames=FALSE,+ width=c(4,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8),append=TRUE,justify='right') I get the following error: Error in data.frame(colname = colnamesMy, nlevels = 0, position = 0, width 0, : arguments imply differing number of rows: 0, 1 In addition: Warning message: In write.fwf(outframe, file = outfile1, sep = "", quote = FALSE, : recycling 'width' I can't see the reason for this. The data in outframe are all numeric, and it worked on the Mac, and outframe has 7 rows on Windows and on the Mac, so I am not sure what is going on here. Here is my traceback() and sessionInfo() in case it helps:>traceback()3: stop("arguments imply differing number of rows: ", paste(unique(nrows), collapse = ", ")) 2: data.frame(colname = colnamesMy, nlevels = 0, position = 0, width = 0, digits = 0, exp = 0, stringsAsFactors = FALSE) 1: write.fwf(outframe, file = outfile1, sep = "", quote = FALSE, rownames = FALSE, colnames = FALSE, width = c(4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8), append = TRUE, justify = "right")> sessionInfo()R version 2.10.1 (2009-12-14) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] splines stats graphics grDevices utils datasets methods base other attached packages: [1] doBy_4.0.5 survival_2.35-7 gdata_2.7.1 chron_2.3-34 loaded via a namespace (and not attached): [1] cluster_1.12.1 grid_2.10.1 gtools_2.6.1 Hmisc_3.7-0 [5] lattice_0.17-26 Matrix_0.999375-33>Any advice on this will be much appreciated. Thanks. -- View this message in context: http://r.789695.n4.nabble.com/Write-fwf-works-from-Mac-throws-different-number-of-row-error-in-Windows-tp2243965p2243965.html Sent from the R help mailing list archive at Nabble.com.
Duncan Murdoch
2010-Jun-05 14:04 UTC
[R] Write.fwf works from Mac, throws different number of row error in Windows
You need to give us something reproducible or we won't likely be able to help you. Put together a small example that illustrates the problem, and it will likely be fixed pretty quickly, or your error will be pointed out. (You need to give us a way to construct outframe, we don't have it.) Duncan Murdoch mazibuko wrote:> Hello, > > I am having a problem with write.fwf in Windows. I wrote a code to ingest a > number of text files with weather data in them, process them, and then > output a text file with two parts: 1) a set of column names, 2) the > processed data table. > > I wrote and tested the program on my Mac, and it worked fine. However, on > the windows machine, where I intend the work to be done, when I run the > following line (last line of the script): > > >> write.fwf(outframe,file=outfile1,sep="",quote=FALSE,rownames=FALSE,colnames=FALSE, >> > + > width=c(4,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8),append=TRUE,justify='right') > > I get the following error: > > Error in data.frame(colname = colnamesMy, nlevels = 0, position = 0, width > 0, : > arguments imply differing number of rows: 0, 1 > In addition: Warning message: > In write.fwf(outframe, file = outfile1, sep = "", quote = FALSE, : > recycling 'width' > > I can't see the reason for this. The data in outframe are all numeric, and > it worked on the Mac, and outframe has 7 rows on Windows and on the Mac, so > I am not sure what is going on here. > > Here is my traceback() and sessionInfo() in case it helps: > > >> traceback() >> > 3: stop("arguments imply differing number of rows: ", paste(unique(nrows), > collapse = ", ")) > 2: data.frame(colname = colnamesMy, nlevels = 0, position = 0, width = 0, > digits = 0, exp = 0, stringsAsFactors = FALSE) > 1: write.fwf(outframe, file = outfile1, sep = "", quote = FALSE, > rownames = FALSE, colnames = FALSE, width = c(4, 8, 8, 8, > 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8), append = TRUE, > justify = "right") > >> sessionInfo() >> > R version 2.10.1 (2009-12-14) > i386-pc-mingw32 > > locale: > [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United > States.1252 > [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C > [5] LC_TIME=English_United States.1252 > > attached base packages: > [1] splines stats graphics grDevices utils datasets methods > base > > other attached packages: > [1] doBy_4.0.5 survival_2.35-7 gdata_2.7.1 chron_2.3-34 > > loaded via a namespace (and not attached): > [1] cluster_1.12.1 grid_2.10.1 gtools_2.6.1 Hmisc_3.7-0 > [5] lattice_0.17-26 Matrix_0.999375-33 > > > Any advice on this will be much appreciated. > > Thanks. > > > > > >
Apparently Analagous Threads
- data file - function write.fwf - library gdata
- Wish: change behaviour of header in read.fwf (PR#9252)
- comment.char in read.fwf (PR#1297)
- comment.char in read.fwf (PR#1298)
- Any way to get read.table.ffdf() (in the ff package) to pass colClasses or comment.char parameters through to read.fwf() ?