Skip to content

load data for mypkg-Ex.R

6 messages · Jason Sinnwell, Thomas Lumley, Roger Koenker +2 more

#
Using R 1.7.1 in Solaris

I'm developing a package for both Splus and R, and I'm trying to use all the 
same files for R and Splus, both function files and help files.  I have two 
questions.

1) The file made by R CMD check to run .Rd-examples posts examples from files in 
alphabetical order.  Is it okay/recommended/common-practice to set up all the 
example data in the first two (alphabetically-sorted) examples and assume that 
data exists for the rest of the examples?  

2)  Since data() is not understood by Splus, I don't want to put a 
	     > data(example.data) 
in the sgml file because then the Splus example would not run as data() doesn't 
exist there.  Is there a spot I can make sure this data is loaded when running 
the examples, but not to load the data every time you load the library, as it 
would take up unnecessary space.  It is a ~~220 x 25 data.frame, is that enough 
size to worry about this? 
I'm considering using the NAMESPACE or .First.lib() within zzz.R but that would 
load the data every time the library is loaded.  Also considering something 
like:
In the example but that would create confusion for users.  

Thanks for your suggestions.

+--------------------------+
|Jason Sinnwell, M.S.   |
|Mayo Clinic, Rochester    |
#
On Fri, 27 Feb 2004, Jason Sinnwell wrote:

            
No.  In fact, it is specifically disallowed.
I wouldn't think it was big enough to worry seriously about
You could define a function

if (is.R())
  setupData<-data
else
  setupData<-function(...) invisible(NULL)

and then use setupData() instead of data(), or you could look at what MASS
does using delay() to autoload data as needed.


	-thomas
#
On Fri, 27 Feb 2004, Jason Sinnwell wrote:

            
That does not work: the workspace is cleared after each help file.  As 
from the next release, the search path is restored too.
Probably not: but use object.size() to find out.
Take a look at how package MASS does this, via a promise.
#
On a related note.... is there a convention for cleaning up the detritus
after running

	example(foo)

I suppose sometimes users would like to have access to the objects
that were created in the course of this, but perhaps more likely they
would prefer that they were vaporized.   I'm finding this also an issue
in writing vignettes,  but my main concern is finding a good way to
handle this in writing .Rd files.


url:	www.econ.uiuc.edu/~roger/my.html	Roger Koenker
email	rkoenker at uiuc.edu			Department of Economics
vox: 	217-333-4558				University of Illinois
fax:   	217-244-6678				Champaign, IL 61820
On Fri, 27 Feb 2004, Prof Brian Ripley wrote:

            
#
You mean, 

    example(foo,local=TRUE) 

?

Roger Koenker <roger at ysidro.econ.uiuc.edu> writes:

  
    
#
On Fri, 27 Feb 2004, Roger Koenker wrote:

            
We tend only to clean up temporary objects, and the search path.
As Tony says, users can call example() with local=TRUE, and the checking 
code tidies up after each help file.  There are several examples of one 
help file calling example() on another and working further with the same 
objects.