Re: [R] Converting pc files to unix

From: Constantinos Antoniou <costas_at_mit.edu>
Date: Wed 04 May 2005 - 19:03:02 EST

On 4 בת 2005, at 11:41 נל, Uwe Ligges wrote:

> Hai Lin wrote:
>
>> Hello R users, I have R script files writen in my pc laptop. I
>> encountered problems when I run those files in R in Mac OS X
>> (10.3.5). Are there any ways in R that can make .R files executable?
>
>
> It should work, at once, given you have not used Windows specific
> commands, hard coded paths etc...
>
> Uwe Ligges
>

Hai,

On the mac, try to open the files in a "unixy" editor, such as emacs, pico, vi. If your file looks something like this (look for ^M):

first line of R commands^Msecond line of R commands^Metc

then the problem is line endings (that are different between platforms).

To fix this, you can open the file(s) in an editor, e.g. SubEthaEdit (free for personal and educational use) and then change the line endings (Format->Line endings->Convert to unix line endings..)

Another approach (useful if you want to batch-convert a lot of files) is to run a script like this:

  #!/bin/sh

     tr '\r' '\n' < $1 >MKTMP001
     mv -f MKTMP001 $1

You can save this as a file, e.g. call it stripCtrlM, make it executable (chmod +x stripCtrlM) and run it:

stripCtrlM filesWithCtrlM.R

or stripCtrlM *.R to convert all .R files in a directory

Hope this helps,

Costas

>
>
>> Thanks in advance
>> Kevin
>> __________________________________________________
>> [[alternative HTML version deleted]]
>> ______________________________________________
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
>> http://www.R-project.org/posting-guide.html
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>

-- 
Constantinos Antoniou, Ph.D.
Massachusetts Institute of Technology
Intelligent Transportation Systems Program
77 Massachusetts Ave., Rm. 1-249, Cambridge, MA 02139

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Wed May 04 19:10:11 2005

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 06 May 2006 - 04:10:03 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.