[R] Changing text file to .r format

Spencer Boucher spencer at spencerboucher.com
Sat Nov 7 00:34:16 CET 2015

There is no fundamental difference between an .R file and a .txt 
file. They are both just text files; all you are doing is changing 
the name. This Stack Overflow question shows how to use 
`file.rename` to do 
so. http://stackoverflow.com/a/10759083/1850696. 

Chattopadhyay, Somsubhra writes:

> Dear all, 
> I am a beginner in R and want to ask a simple question. I have a 
> code file in text format which I need to change to .r format 
> only. For example now it is RHtestsV4.r.txt which needs to be 
> changed to just RHtestsV4.r. I tried this 
> sub("^([^.]*).*", "\\1", 'RHtestsV4.r.txt') [1] "RHtestsV4" 
> But this didn't seem to work as again when I try to call the 
> function using source("RHtestsV4.r") The error message is 
> Error in file(filename, "r", encoding = encoding) : 
>   cannot open the connection 
> In addition: Warning message: In file(filename, "r", encoding = 
> encoding) : 
>   cannot open file 'RHtestsV4.r': No such file or directory 
> I think it is due to the format of the file. Please help me to 
> convert the file to .r format. 
> Thanks Som

More information about the R-help mailing list