Running R from windows command prompt

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Running R from windows command prompt

siddharth arun
1. I have a R program in a file say "functions.R".
I load the "functions.R" file the R using source("function.R") and then call
functionsf1(), f2() etc. which are declared and defined within "function.R"
 file.
I also need to load a couple of R libraries using library() before I can
use f1(), f2() etc.

My question is can I acheive all this (i.e. calling function f1() and f2())
from the windows prompt without opening the R environment ? If yes then how?


2. Also, Is there any way to scan strings directly. Like scan() function
only scans numerical values. Is there any way to scan strings?

--
Siddharth Arun,
4th Year Undergraduate student
Industrial Engineering and Management,
IIT Kharagpur

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
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.
Reply | Threaded
Open this post in threaded view
|

Re: Running R from windows command prompt

Uwe Ligges-3


On 28.06.2011 11:54, siddharth arun wrote:
> 1. I have a R program in a file say "functions.R".
> I load the "functions.R" file the R using source("function.R") and then call
> functionsf1(), f2() etc. which are declared and defined within "function.R"
>   file.
> I also need to load a couple of R libraries using library() before I can
> use f1(), f2() etc.
>
> My question is can I acheive all this (i.e. calling function f1() and f2())
> from the windows prompt without opening the R environment ? If yes then how?


Put all the code into a file, e.g. "foo.R", and run

R CMD BATCH foo.R from the windows command shell.


> 2. Also, Is there any way to scan strings directly. Like scan() function
> only scans numerical values. Is there any way to scan strings?

Yes, it is called scan() which is for arbitrary data, including
character(). See ?scan. Otherwise, you may want to look into ?readLines

Uwe Ligges

______________________________________________
[hidden email] mailing list
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.
Reply | Threaded
Open this post in threaded view
|

Re: Running R from windows command prompt

siddharth arun
Thanks for your help.

I tried the way you mentioned for my first question. But I am not getting
any results.
Can you please explain in detail the process through which I can run a R
code from windows command prompt.

2011/6/28 Uwe Ligges <[hidden email]>

>
>
> On 28.06.2011 11:54, siddharth arun wrote:
>
>> 1. I have a R program in a file say "functions.R".
>> I load the "functions.R" file the R using source("function.R") and then
>> call
>> functionsf1(), f2() etc. which are declared and defined within
>> "function.R"
>>  file.
>> I also need to load a couple of R libraries using library() before I can
>> use f1(), f2() etc.
>>
>> My question is can I acheive all this (i.e. calling function f1() and
>> f2())
>> from the windows prompt without opening the R environment ? If yes then
>> how?
>>
>
>
> Put all the code into a file, e.g. "foo.R", and run
>
> R CMD BATCH foo.R from the windows command shell.
>
>
>
>  2. Also, Is there any way to scan strings directly. Like scan() function
>> only scans numerical values. Is there any way to scan strings?
>>
>
> Yes, it is called scan() which is for arbitrary data, including
> character(). See ?scan. Otherwise, you may want to look into ?readLines
>
> Uwe Ligges
>
>


--
Siddharth Arun,
4th Year Undergraduate student
Industrial Engineering and Management,
IIT Kharagpur

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
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.
Reply | Threaded
Open this post in threaded view
|

Re: Running R from windows command prompt

Mike Marchywka




> To: [hidden email]
> CC: [hidden email]
> Subject: Re: [R] Running R from windows command prompt
>
> Thanks for your help.
>
> I tried the way you mentioned for my first question. But I am not getting
> any results.
> Can you please explain in detail the process through which I can run a R
> code from windows command prompt.

While your problem likely has nothing to do with windoh's, I would suggest
you go get cygwin ( see google) and use that. I and probably others
have lots of scripts that work there and on linux. Bash scripts are
a better way to proceed if you want to do more than a test case and
they integrate with lots of other existing things.


>
> 2011/6/28 Uwe Ligges <[hidden email]>
>
> >
> >
> > On 28.06.2011 11:54, siddharth arun wrote:
> >
> >> 1. I have a R program in a file say "functions.R".
> >> I load the "functions.R" file the R using source("function.R") and then
> >> call
> >> functionsf1(), f2() etc. which are declared and defined within
> >> "function.R"
> >>  file.
> >> I also need to load a couple of R libraries using library() before I can
> >> use f1(), f2() etc.
> >>
> >> My question is can I acheive all this (i.e. calling function f1() and
> >> f2())
> >> from the windows prompt without opening the R environment ? If yes then
> >> how?
> >>
> >
> >
> > Put all the code into a file, e.g. "foo.R", and run
> >
> > R CMD BATCH foo.R from the windows command shell.
> >
> >
> >
> >  2. Also, Is there any way to scan strings directly. Like scan() function
> >> only scans numerical values. Is there any way to scan strings?
> >>
> >
> > Yes, it is called scan() which is for arbitrary data, including
> > character(). See ?scan. Otherwise, you may want to look into ?readLines
> >
> > Uwe Ligges
> >
> >
>
>
> --
> Siddharth Arun,
> 4th Year Undergraduate student
> Industrial Engineering and Management,
> IIT Kharagpur
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> 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.
     
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
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.
Reply | Threaded
Open this post in threaded view
|

Re: Running R from windows command prompt

Uwe Ligges-3


On 28.06.2011 13:56, Mike Marchywka wrote:

>
>
>
>
>> To: [hidden email]
>> CC: [hidden email]
>> Subject: Re: [R] Running R from windows command prompt
>>
>> Thanks for your help.
>>
>> I tried the way you mentioned for my first question. But I am not getting
>> any results.
>> Can you please explain in detail the process through which I can run a R
>> code from windows command prompt.


Either save your results using a function call in the foo.R file or just
look into the foo.Rout file R generated for you.


> While your problem likely has nothing to do with windoh's, I would suggest
> you go get cygwin ( see google) and use that.

Sure you can do, but note that cygwin is not officially supported.


> I and probably others
> have lots of scripts that work there and on linux. Bash scripts are
> a better way to proceed if you want to do more than a test case and
> they integrate with lots of other existing things.

R CMD BATCH foo.R behaves almost the same way in both Windows command
shell and the bash.

Best,
Uwe Ligges




>
>>
>> 2011/6/28 Uwe Ligges<[hidden email]>
>>
>>>
>>>
>>> On 28.06.2011 11:54, siddharth arun wrote:
>>>
>>>> 1. I have a R program in a file say "functions.R".
>>>> I load the "functions.R" file the R using source("function.R") and then
>>>> call
>>>> functionsf1(), f2() etc. which are declared and defined within
>>>> "function.R"
>>>>   file.
>>>> I also need to load a couple of R libraries using library() before I can
>>>> use f1(), f2() etc.
>>>>
>>>> My question is can I acheive all this (i.e. calling function f1() and
>>>> f2())
>>>> from the windows prompt without opening the R environment ? If yes then
>>>> how?
>>>>
>>>
>>>
>>> Put all the code into a file, e.g. "foo.R", and run
>>>
>>> R CMD BATCH foo.R from the windows command shell.
>>>
>>>
>>>
>>>   2. Also, Is there any way to scan strings directly. Like scan() function
>>>> only scans numerical values. Is there any way to scan strings?
>>>>
>>>
>>> Yes, it is called scan() which is for arbitrary data, including
>>> character(). See ?scan. Otherwise, you may want to look into ?readLines
>>>
>>> Uwe Ligges
>>>
>>>
>>
>>
>> --
>> Siddharth Arun,
>> 4th Year Undergraduate student
>> Industrial Engineering and Management,
>> IIT Kharagpur
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list
>> 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.
>

______________________________________________
[hidden email] mailing list
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.
Reply | Threaded
Open this post in threaded view
|

Re: Running R from windows command prompt

Arun.stat
In reply to this post by siddharth arun
Hi Siddharth, many experts already answered your query, however I
would like to share how I run R in command prompt:

1. open command prompt
2. change working directory: cd C:\................\R-2.13.0\bin\i386
(put the entire path here, however many people might find this step
weird, you can have better management setting window's path variable
appropriately)
3. type R.exe

You can use R within command prompt with same efficiency. However most
awkward thing I find in this process is you can never copy-paste any
code. So everything you need to type there manually!

HTH
_____________________________________________________

Arun Kumar Saha, FRM
QUANTITATIVE RISK AND HEDGE CONSULTING SPECIALIST
Visit me at: http://in.linkedin.com/in/ArunFRM

______________________________________________
[hidden email] mailing list
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.
Reply | Threaded
Open this post in threaded view
|

Re: Running R from windows command prompt

Robert Baer
Subject: Re: [R] Running R from windows command prompt

Hi Siddharth, many experts already answered your query, however I
would like to share how I run R in command prompt:

1. open command prompt
2. change working directory: cd C:\................\R-2.13.0\bin\i386
(put the entire path here, however many people might find this step
weird, you can have better management setting window's path variable
appropriately)
3. type R.exe

You can use R within command prompt with same efficiency. However most
awkward thing I find in this process is you can never copy-paste any
code. So everything you need to type there manually!
-------------------
Actually, you can 'cut and paste' from at Windows Cmd prompt.  It is done by
clicking the
C: icon in the upper left of the command window, choosing edit, and 'copy'
or 'paste'
as desired.

Rob

HTH
_____________________________________________________

Arun Kumar Saha, FRM
QUANTITATIVE RISK AND HEDGE CONSULTING SPECIALIST
Visit me at: http://in.linkedin.com/in/ArunFRM

______________________________________________
[hidden email] mailing list
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.

______________________________________________
[hidden email] mailing list
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.
Reply | Threaded
Open this post in threaded view
|

Re: Running R from windows command prompt

Michael Sumner-2
On Wed, Jun 29, 2011 at 1:51 AM, Robert Baer <[hidden email]> wrote:
> Subject: Re: [R] Running R from windows command prompt
>
<snip>
> -------------------
> Actually, you can 'cut and paste' from at Windows Cmd prompt.  It is done by
> clicking the
> C: icon in the upper left of the command window, choosing edit, and 'copy'
> or 'paste'
> as desired.
>

Or shortcut to the Edit menu by right-click in the window.

It is copying out that is weirdest, and worth knowing I think:
Edit/Mark, then select the text and press Enter to copy it to the
clipboard.

Cheers, Mike.

> Rob
>
> HTH
> _____________________________________________________
>
> Arun Kumar Saha, FRM
> QUANTITATIVE RISK AND HEDGE CONSULTING SPECIALIST
> Visit me at: http://in.linkedin.com/in/ArunFRM
>
> ______________________________________________
> [hidden email] mailing list
> 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.
>
> ______________________________________________
> [hidden email] mailing list
> 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.
>



--
Michael Sumner
Institute for Marine and Antarctic Studies, University of Tasmania
Hobart, Australia
e-mail: [hidden email]

______________________________________________
[hidden email] mailing list
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.
Reply | Threaded
Open this post in threaded view
|

Re: Running R from windows command prompt

Orvalho Augusto
If you want to have R available under command prompt you need to add
the R executable to the PATH environmental variable doing this (On
Windows XP and it is similar on Vista or 7):
start> right click on My Computer > Choose properties > Advanced >
Envonment variables > Under system variables choose Path and click
EDIT > on variable value at the end of it add ;C:\Program
Files\R\R-2.13.0\bin

Click OK. And you are done.

The C:\Program Files\R\R-2.13.0\bin is the place you have the R
executables which you can find from explorer.

After that your can call R from command prompt like
R CMD BATCH e.g

Good luck
Caveman


On 6/29/11, Michael Sumner <[hidden email]> wrote:

> On Wed, Jun 29, 2011 at 1:51 AM, Robert Baer <[hidden email]> wrote:
>> Subject: Re: [R] Running R from windows command prompt
>>
> <snip>
>> -------------------
>> Actually, you can 'cut and paste' from at Windows Cmd prompt.  It is done
>> by
>> clicking the
>> C: icon in the upper left of the command window, choosing edit, and 'copy'
>> or 'paste'
>> as desired.
>>
>
> Or shortcut to the Edit menu by right-click in the window.
>
> It is copying out that is weirdest, and worth knowing I think:
> Edit/Mark, then select the text and press Enter to copy it to the
> clipboard.
>
> Cheers, Mike.
>
>> Rob
>>
>> HTH
>> _____________________________________________________
>>
>> Arun Kumar Saha, FRM
>> QUANTITATIVE RISK AND HEDGE CONSULTING SPECIALIST
>> Visit me at: http://in.linkedin.com/in/ArunFRM
>>
>> ______________________________________________
>> [hidden email] mailing list
>> 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.
>>
>> ______________________________________________
>> [hidden email] mailing list
>> 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.
>>
>
>
>
> --
> Michael Sumner
> Institute for Marine and Antarctic Studies, University of Tasmania
> Hobart, Australia
> e-mail: [hidden email]
>
> ______________________________________________
> [hidden email] mailing list
> 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.
>

______________________________________________
[hidden email] mailing list
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.