Bug 16529 - write() adding wrong separator char
Summary: write() adding wrong separator char
Alias: None
Product: R
Classification: Unclassified
Component: I/O (show other bugs)
Version: R 3.2.1
Hardware: x86_64/x64/amd64 (64-bit) Windows 64-bit
: P5 normal
Assignee: R-core
Depends on:
Reported: 2015-09-04 09:30 UTC by Joey Ward
Modified: 2015-11-02 11:00 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Joey Ward 2015-09-04 09:30:24 UTC
I start by selecting a column of a data frame and converting it to a one line matrix so i can write it to a single line of a file. Using the write() command with sep = "," so the object is written to a single line with "," between each element of the matrix the output file contains some elements separated with a ";" instead of ",". The ";" seem to appear randomly. 

Here is the relevant code:

p_0.01_chr_rs <- as.character(p_0.01_chr$SNP)
p_0.01_chr_rs <- as.matrix(t(p_0.01_chr_rs))
if(j== 1){
        write(rs_codes[[k]][1:if(length(rs_codes[[k]]) > 9999) 9999 else length(rs_codes[[k]])], outfile_script_chr, sep=",",ncolumns = length(rs_codes[[k]]), append=T)
        counter <- counter + 10000
      }else if(j == ceiling(length(rs_codes[[k]])/10000)){
        write(rs_codes[[k]][counter:length(rs_codes[[k]])], outfile_script_chr, sep=",",ncolumns = length(rs_codes[[k]]), append=T)
        write(rs_codes[[k]][counter:(counter+9999)], outfile_script_chr, sep=",",ncolumns = 10000, append=T)
        counter <- counter + 10000
Comment 1 Martin Maechler 2015-11-02 11:00:31 UTC
We need a (minimal)   ** reproducible **  example;
code snippets using data you have but we don't  are not enough.

Thank you in advance for providing code with such a reproducible example.