[R] Write.fwf works from Mac, throws different number of row error in Windows

Duncan Murdoch murdoch.duncan at gmail.com
Sat Jun 5 16:04:15 CEST 2010


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. 
>
>
>   
>
>
>



More information about the R-help mailing list