[R] R not recognized in command line
egregory2007 at yahoo.com
Fri Jan 7 04:00:58 CET 2011
I was also having some trouble using RPy2 (spoiler alert: I gave up!) to write a
GUI for some R scripts I've written. I found a workaround to integrate R and
python without using that module. The idea is:
1. Write R scripts you want to use in python. I have a file with all of the
functions I'll need to use.
2. Write python code that writes R code (according to whatever inputs you
want...) calling the functions in your script. For example, if the R function I
wanted to use was "sum", I'd have users input two numbers in python, and have
python create the string "sum(867, 5309)"
3. Open the file with the Rscript using python, and add "sum(867, 5309)" to the
end of it.
4. Create the string t = "cd C:\Program Files\R\R-2.11.0\bin&Rscript sum.r" in
python, where "sum.r" is a file with the "sum" function, to which we added the
string "sum(867, 5309)" using python and "C:\...\bin" is whatever directory your
R installation is in.
5. Finally, open the shell as a subprocess using python and send "t" to the
This method works if you don't need to see the output of the R script in the
python console. If you really want to see that, have R write the output into
some file that python can open and open that with python script! I did all this
without any experience with python (I'm alright with R), so you may even find
Student Assistant, California EPA
CSU Sacramento, Mathematics
----- Original Message ----
From: Aaditya Nanduri <aaditya.nanduri at gmail.com>
To: Gabor Grothendieck <ggrothendieck at gmail.com>
Cc: r-help at r-project.org
Sent: Thu, January 6, 2011 6:23:46 PM
Subject: Re: [R] R not recognized in command line
I really appreciate all your help but I've already tried everything that has
I changed the path to every possible combination that leads to an R
executable...and nothing seems to work.
I've checked to see that Im typing it right. I've also asked my sister to
make sure (a fresh set of eyes is always helpful).
The only thing that work are navigating to the folder holding the R
executable (R_HOME/bin) and the batchscripts. However, this doesnt help me
in working with rpy2.
On Wed, Jan 5, 2011 at 9:59 AM, Gabor Grothendieck
<ggrothendieck at gmail.com>wrote:
> On Wed, Jan 5, 2011 at 10:41 AM, Duncan Murdoch
> <murdoch.duncan at gmail.com> wrote:
> > On 11-01-05 8:51 AM, Joshua Wiley wrote:
> >> Hi Aaditya,
> >> I assume you are running some variant of Windows and by the "prompt in
> >> DOS" you are using cmd.exe.
> >> Perhaps you are already, but from your examples it looks like either
> >> A) you are not in the same directory as R or B) are not adding the
> >> path to R in the command. For example, on Windows I always install R
> >> under C:\R\ so for me inside cmd.exe:
> >> C:\directory> C:\R\R-devel\bin\x64\R
> >> [[[R starts here]]]
> >> alternately you could switch directories over and then just type "R"
> >> at the console:
> >> C:\directory> cd C:\R\R-devel\bin\x64\
> >> C:\R\R-devel\bin\x64> R
> >> [[[R starts here]]]
> >> or since you have set the environment variables:
> >> C:\directory> %R_HOME%\bin\x64\R
> >> [[[R starts here]]]
> >> Alternately, edit the PATH environment variable in Windows and add the
> >> path to R (i.e., R_HOME\bin\i386\ or whatever it is for you), and you
> >> should be able to just enter "R" at the command prompt and have it
> >> start.
> > Editing the PATH is probably the best approach, but a lot of people get
> > wrong because of misunderstanding how it works:
> > - If you change PATH in one process the changes won't propagate
> > else, and will be lost as soon as you close that process. That could be
> > cmd window, or an R session, or just about any other process that lets
> > change environment variables.
> > - If you want to make global changes to the PATH, you need to do it in
> > control panel "System|Advanced|Environment variables" entries.
> > - Often it is good enough to use a more Unix-like approach, and only
> > the change at startup of the cmd processor. You use the /k option when
> > starting cmd if you want to run something on startup.
> You can also use Rcmd.bat, R.bat, Rgui.bat, etc. found at
> Just put any you wish to use anywhere on your path and it will work on
> all cmd instances and will also work when you install a new version of
> R since it looks up R's location in the registry.
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
aaditya.nanduri at gmail.com
[[alternative HTML version deleted]]
R-help at r-project.org mailing list
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