[R] Question about Line Ending Choice

Stephen H. Dawson, DSL @erv|ce @end|ng |rom @hd@w@on@com
Thu Sep 29 19:10:45 CEST 2022


Awesome idea, Jorgen. Thanks for the input.

As expected, it was smart to ask about matter this before I undertook my 
build effort.


Kindest Regards,
*Stephen Dawson, DSL*
/Executive Strategy Consultant/
Business & Technology
+1 (865) 804-3454
http://www.shdawson.com


On 9/28/22 12:06, Jorgen Harmse via R-help wrote:
> eol seems to be the parameter to use, but the answers so far appear to assume that the file is created on a Mac. For example, I think that �\r\n� on Windows would produce CR CR LF. I don�t have both systems handy (so I can�t test), but I think you should use raw to specify the bytes you want.
>
> # I think the following are independent of the OS on which you are writing the file.
> CR <- rawToChar(as.raw(13))
> LF <- rawToChar(as.raw(10))
> if missing(target)
>    # Hope that it matches the machine on which you are writing the file.
>    eol <- �\n�
> else if (target==�Windows�)
>    eol <- c(CR,LF)
> else if (target %in% c(�Unix�,�Mac�))
>    eol <- LF
> else if �.
> else
>    stop(�Unexpected target.�)
>
> write.table(eol=eol, �.)
>
> Regards,
> Jorgen Harmse.
>
>
>
> Message: 7
> Date: Tue, 27 Sep 2022 11:35:54 -0400
> From: "Stephen H. Dawson, DSL" <service using shdawson.com>
> To: Bert Gunter <bgunter.4567 using gmail.com>
> Cc: r-help <r-help using r-project.org>
> Subject: Re: [R] Question about Line Ending Choice
> Message-ID: <04e458aa-e5f5-c932-da3c-1aa35db7daf7 using shdawson.com>
> Content-Type: text/plain; charset="utf-8"; Format="flowed"
>
> Hi Bert,
>
>
> Thanks for the reply.
>
> I did see the parameter, but was not sure if this is the correct
> parameter to reference. I also see it in write.csv.
>
> I take it you are saying the eol parameter is the best practice for
> exporting from R using these functions. Am I correct or is there another
> option other than write.csv and write.table I should be considering?
>
>
> Thanks,
> *Stephen Dawson, DSL*
> /Executive Strategy Consultant/
> Business & Technology
> +1 (865) 804-3454
> http://www.shdawson.com
>
>
> On 9/27/22 11:29, Bert Gunter wrote:
>> Did you not see the "eol" parameter in write.table ?
>>
>> Bert
>>
>> On Tue, Sep 27, 2022 at 8:23 AM Stephen H. Dawson, DSL via R-help
>> <r-help using r-project.org> wrote:
>>
>>      Hi All,
>>
>>
>>      I am writing with a question about choosing the line ending aspect
>>      of a
>>      file, please.
>>
>>      I use write.csv and write.table to export work to CSV files and TXT
>>      files. I am planning now on how to share my work with the Windows
>>      crowd
>>      beyond only sharing with the Linux crowd. I use my text editor to
>>      flip
>>      the line ending option from Linux to Windows after exporting. This is
>>      inefficient for me to accomplish if I ramp up production as I expect
>>      will occur.
>>
>>      Staying with the character encoding of UTF-8 seems fine for now from
>>      what I understand I need to deliver to my customers.
>>
>>      What seems more efficient to me is to learn how to use R to define
>>      the
>>      line ending aspect of the exported file. I have not found if this
>>      is an
>>      option within R.
>>
>>      QUESTION
>>      Is it possible within R to define the line ending aspect of file
>>      output?
>>
>>
>>      Kindest Regards,
>>      --
>>      *Stephen Dawson, DSL*
>>      /Executive Strategy Consultant/
>>      Business & Technology
>>      +1 (865) 804-3454
>>      http://www.shdawson.com
>>
>>      ______________________________________________
>>      R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>      https://stat.ethz.ch/mailman/listinfo/r-help
>>      PLEASE do read the posting guide
>>      http://www.R-project.org/posting-guide.html
>>      <http://www.R-project.org/posting-guide.html>
>>      and provide commented, minimal, self-contained, reproducible code.
>>
>
>
> **********
>
> 	[[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list