Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: New version of -rsource- on SSC
From
"Roger B. Newson" <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: New version of -rsource- on SSC
Date
Mon, 03 Mar 2014 12:35:09 +0000
Thanks as always to Kit Baum, a new version of the -rsource- package is
now available for download from SSC. In Stata, use the -ssc- command to
do this, or -adoupdate- if you already have an old version of -rsource-.
The -rsource- package is described as below on my website, and allows
users to run R from inside Stata, possibly inputting Stata disk datasets
created by the Stata program and outputting more Stata disk datasets for
input by the Stata program after R has run. The new version adds a
-terminator()- option, allowing the user to input the R program from an
instream sequence of lines, terminated by a terminator string. This
allows the user to write recombinant do-files, in which one or more R
programs can be embedded in a Stata program. As in:
. sysuse auto, clear
. describe, full
. saveold myauto.dta, replace
. rsource, terminator(END_OF_R)
. library(foreign);
. rauto<-read.dta("myauto.dta", convert.f=TRUE);
. rauto;
. attributes(rauto);
. q();
. END_OF_R
This example creates an old-format Stata dataset (which R can read), and
then runs an R program, terminated by the string END_OF_R, which inputs
the old-format Stata dataset into an R data frame, and lists the data
frame, and also lists the R attributes belonging to an R data frame
input from a Stata dataset. (Such an R data frame has attributes not
always present for other R data frames, such as $var.labels, which is a
string vector of variable labels). However, it would probably be more
usual to input the R data frame into R packages implementing methods not
yet available in Stata.
I would like to thank Alan Riley, Kerry Kammire and Karen Hickson of
StataCorp for very helpfully explaining to me about how to use the
unpublicized -_request2(macroname)- option of the -display- command,
without which these recombinant do-files would not be possible.
Best wishes
Roger
--
Roger B Newson BSc MSc DPhil
Lecturer in Medical Statistics
Respiratory Epidemiology, Occupational Medicine
and Public Health Group
National Heart and Lung Institute
Imperial College London
Royal Brompton Campus
Room 33, Emmanuel Kaye Building
1B Manresa Road
London SW3 6LR
UNITED KINGDOM
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Email: [email protected]
Web page: http://www.imperial.ac.uk/nhli/r.newson/
Departmental Web page:
http://www1.imperial.ac.uk/medicine/about/divisions/nhli/respiration/popgenetics/reph/
Opinions expressed are those of the author, not of the institution.
---------------------------------------------------------------------------
package rsource from http://www.imperial.ac.uk/nhli/r.newson/stata10
---------------------------------------------------------------------------
TITLE
rsource: Run R from inside Stata
DESCRIPTION/AUTHOR(S)
rsource runs an R source program, from an inline sequence of lines
and/or from a file, in batch mode from within Stata, optionally
listing the R output and/or the R source code to the Stata Results
window and/or the Stata log file. This allows the user to call R
at a point in the execution of a Stata program to input data files
previously created by Stata and/or to create output data files for
later input by Stata. The R software system must be installed on
the user's system if the rsource package is to work.
Author: Roger Newson
Distribution-Date: 28february2014
Stata-Version: 10
INSTALLATION FILES (click here to install)
rsource.ado
rsource.sthlp
---------------------------------------------------------------------------
(click here to return to the previous screen)
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/