Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

writedlm - issues with line breaks on Windows #15

Open
rowlesmr opened this issue Oct 13, 2015 · 5 comments
Open

writedlm - issues with line breaks on Windows #15

rowlesmr opened this issue Oct 13, 2015 · 5 comments
Labels

Comments

@rowlesmr
Copy link

When writing an array with writedlm on Windows, lines are not terminated with /r/n.

julia> rnd = rand(2,2)
2x2 Array{Float64,2}:
 0.417898  0.534031
 0.593108  0.909771
julia> writedlm("out.txt", rnd)

-> .41789803012680227 .5340308732027403.5931077439922414 .9097713865838699

Expected behaviour: on a Windows system, the Windows line break would be used.

Julia Version 0.4.0
Commit 0ff703b* (2015-10-08 06:20 UTC)
Platform Info:
  System: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.3
@tkelman
Copy link

tkelman commented Oct 13, 2015

I'd rather not, personally. Aside from notepad.exe, what programs can't handle unix line endings by now? If you really want \r\n, you can run(unix2dos out.txt)

@nalimilan
Copy link
Member

I just discovered RFC 4180 (the only one about CSV) recommends using CRLF line endings:

As per section 4.1.1. of RFC 2046 [3], this media type uses CRLF
to denote line breaks. However, implementors should be aware that
some implementations may use other values.

RFC 2046 is about MIME. It sounds too bad not to follow the standard here, but since no standard really exists and it is easy to support both kinds of line breaks, it's not the end of the world. FWIW, R uses \r\n on Windows, and \n elsewhere. At least, always doing the same thing on all platforms sounds like a good idea for Julia.

I guess the question is: does Excel open non-CRLF CSV files correctly by default?

@rowlesmr
Copy link
Author

Excel does open non-CRLF CSV files correctly by default.

@nalimilan
Copy link
Member

Thanks. So is there any specific reason why you'd prefer CRLF?

@rowlesmr
Copy link
Author

I use notepad to view my files as it is quick, light-weight, and doesn't lock files for editing.

Also, I think that it would be throw up the least number of surprises by doing Windows things on Windows computers.

@ViralBShah ViralBShah transferred this issue from JuliaLang/julia Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants