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
--
Somsubhra Chattopadhyay
Graduate Research Assistant
Biosystem and Agricultural Engineering Department
University of Kentucky, Lexington, KY 40546
Email: schattop14 at uky.edu
Cell: 9198026951
[[alternative HTML version deleted]]
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
Perhaps this would be a good time to use your operating system capabilities to
change the name of the file. All you have been doing is mucking with data in R
without affecting the actual file name.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live
Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
On November 6, 2015 11:22:13 AM PST, "Chattopadhyay, Somsubhra"
<sch298 at g.uky.edu> wrote:>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
For reference, also asked here: http://stackoverflow.com/questions/33569737/unable-to-call-a-function-in-r On Sat, Nov 7, 2015 at 4:22 AM, Chattopadhyay, Somsubhra <sch298 at g.uky.edu> wrote:> 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 > -- > Somsubhra Chattopadhyay > Graduate Research Assistant > Biosystem and Agricultural Engineering Department > University of Kentucky, Lexington, KY 40546 > Email: schattop14 at uky.edu > Cell: 9198026951 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.-- Pascal Oettli Project Scientist JAMSTEC Yokohama, Japan