Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: Invoking R from Stata


From   Michael Hanson <[email protected]>
To   [email protected]
Subject   Re: st: RE: Invoking R from Stata
Date   Mon, 01 Dec 2008 19:45:50 -0500

While I'm on the topic of platform independence....

I noticed from -help rsource- that the "Rterm_path" global macro of Roger Newson's -rsource- procedure defaults to a value of "Rterm.exe". In light of Kit Baum's response to David Airey (quoted below), it seems that a more robust solution would be to replace lines 30-32 of rsource.ado:

  if `"`rpath'"'=="" {;
    local rpath "Rterm.exe";
  };

with the following:

  if `"`rpath'"'=="" {;
    if c(os) == "Windows" {;
      local rpath "Rterm.exe";
    };
    else {;
      local rpath "/usr/bin/r";
    };
  };

If I understand Kit's message correctly, the latter executable path is valid for any Unix-based installation of R (including R.app on Mac OS X).

Hope this helps,
Mike


On Dec 1, 2008, at 6:08 PM, Kit Baum wrote:
He is referring to Roger Newson's -rsource- package on SSC.

I just tried it under Mac OS X 10.5 and it works fine. In Stata, do

global Rterm_path "/usr/bin/r"
global Rterm_options `"--vanilla"'

Then if we have a file test.R containing

-----
2+2
q()
-----

. rsource using test.R
Assumed R program path: "/usr/bin/r"


Beginning of R output from source file: test.R

R version 2.6.2 (2008-02-08)
Copyright (C) 2008 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> 2+2
[1] 4
> q()

End of R output from source file: test.R



No doubt by changing the Rterm_options you can alter the way in which it produces output. Note that under *nix there is no separate executable Rterm; it is just the binary executable r. When you install R on Mac OS X, you get R.app, which is the executable that provides the GUI, but under the hood it calls /usr/ bin/r.

Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html


On Dec 1, 2008, at 5:29 PM, David Airey wrote:

Has anyone used _rsource_ with the Apple OS X operating system?

-Dave

On Dec 1, 2008, at 1:00 PM, Martin Weiss wrote:

Line for the server...

That is exactly what -rsource- does, but it also takes care of logging...

HTH
Martin


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Orvalho Augusto
Sent: Monday, December 01, 2008 7:56 PM
To: [email protected]
Subject: Re: st: RE: Invoking R from Stata

Run from stata:
! /path/to/R.exe /path/to/rscriptfile

! means to invoke a shel command.

Caveman

On 12/1/08, Martin Weiss <[email protected]> wrote:

Line for the server...

***********
ssc d rsource
***********

HTH
Martin


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Ljubica
Nedelkoska
Sent: Monday, December 01, 2008 4:38 PM
To: [email protected]
Subject: st: Invoking R from Stata

Dear Statlist members,

I would like to run a file written in R program from a Stata do file. I
would
appreciate if somebody helps me how to invoke R from Stata.

Many thanks!

Ljubica


Ljubica Nedelkoska
PhD student
Research group: "Economics of Innovative Change"
Friedrich Schiller Universität-Jena
+49(0)3641 (9) 43 272


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index