Statalist


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

st: Query re -display request(macmane)-


From   "Newson, Roger B" <r.newson@imperial.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: Query re -display request(macmane)-
Date   Tue, 29 Sep 2009 16:11:34 +0100

I have a query re the -_request()- directive of the -display- command, as described in -[P] display-. (Thanks to Bill Gould and Alan Riley for drawing my attention to this directive at the recent 2009 UK Stata User Meeting.)

Am I right to guess that the -_request()- directive of the -display- command can only accept input from the console, and not from any other channel? And, in particular, am I right to guess that, if I put a -display _request(macname)- command in an ado-file, then it cannot input the next line of the calling do-file, following the call to the ado-file?

What I would REALLY like to do is to write an ado-file that acts something like the -input- command, and inputs the following few lines of the calling do-file as an in-stream input file. For instance, I would like to use my -rsource- package (downloadable from SSC) to run an R program embedded in a Stata do-file. Currently, -rsource- can only link in an R program from a separate file, As in the following code:

**** BEGINNING OF Stata CODE - CUT HERE
save trash1.dta, replace
rsource using nitz2.R
use trash2.dta, clear
**** END OF Stata CODE - CUT HERE

This code saves a dataset -trash1.dta-, then runs an R program in the file -nitz2.R-, and then uses a dataset -trash2.dta-, possibly created by the R program.

I would ideally like to embed an R program in a Stata program, instead of linking it into a Stata program as above. The fantasy Stata code to do this might read as follows:

**** BEGINNING OF FANTASY Stata CODE - CUT HERE
save trash1.dta, replace
rsource, terminator(";;;;")
library(foreign);
wiggles<-read.dta("trash1.dta", convert.f=TRUE);
attach(wiggles);
gptm=2000/(weight*mpg);
detach();
waggles=data.frame(wiggles,gptm);
attach(waggles);
write.dta(waggles, "trash2.dta", version=7);
;;;;
use trash2.dta, clear
**** END OF FANTASY Stata CODE - CUT HERE

This fantasy Stata code first saves a dataset -trash1.dta-, then inputs and executes an R program embedded in the Stata code between the line

rsource, terminator(";;;;")

and the line

;;;;

which is the terminator line for the R code (as specified by the fantasy -terminator()- option of -rsource-).

Unfortunately, when I tried to create a new version of -rsource- with the ability to read embedded files, using the -_request()- directive of the -display- command, it requested the embedded file from the console, instead of reading it from the next few lines of the calling do-file, as I would have preferred. Is there a work-around?

Best wishes

Roger


Roger B Newson BSc MSc DPhil
Lecturer in Medical Statistics
Respiratory Epidemiology 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: r.newson@imperial.ac.uk 
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.


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index