Skip to content

*.R files for user libraries

5 messages · Agustin Lobo, Brian Ripley, Thomas Lumley +1 more

#
Hi!

The Writing R Extensions document (R-exts.pdf) states that,
for creating an R library,

""
The `R' subdirectory contains R code files. The code files to be installed
must start with
a (lower or upper case) letter and have one of the extensions `.R', `.S',
`.q', `.r', or `.s'.
""

Does this mean that each function sould go into
a separate *.R file?

I understand that I can save a given function as

save(test,file="R/test.R")

But I have many functions, should I make that each function
go to a separate file? Is there any utility for doing 
this?

Thanks

Agus

Dr. Agustin Lobo
Instituto de Ciencias de la Tierra (CSIC)
Lluis Sole Sabaris s/n
08028 Barcelona SPAIN
tel 34 93409 5410
fax 34 93411 0012
alobo at ija.csic.es


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Fri, 22 Jun 2001, Agustin Lobo wrote:

            
You can use one of more files as you like.  You can also just concatentate
the small files into one large file via `cat'.

Most packages use one file for each group of functions, as indeed do the R
sources.

  
    
#
On Fri, 22 Jun 2001, Agustin Lobo wrote:

            
No, no, no.  This saves a binary version of the file.  You need to use
dump().
One file or many is ok. Most people find it easier to write the functions
in .R files to begin with, but the new 1.3.0 has an experimental function
package.skeleton() that does some of the work of setting up a package.

It is easier to find things in the documentation if you use our
terminology: you are trying to create a package, not a library. A library
is a place to put packages.


	-thomas

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
3 days later
#
Well, thanks to you all
I've been able to install my first
little package. I've dumped
some of my Splus(PC) functions
to an ascii file (*.R), created
the directory structure and the
DESCRIPTION and INDEX files. Then
I checked and installed with:

R CMD INSTALL -l ~/.R/library Sutilpangea

because I found that I have an .R directory
in my home where a subdirectory .R/library
has links to where the packages really are
(/usr/lib/R/library). Therefore, I decided
to keep  my own packages in .R/library
while the CRAN packages really stay in
/usr/lib/R/library.

Now the only problem is that, by default, R
searches packages in /usr/lib/R/library
because of the value of R_HOME:
/usr/lib/R

It would be better if R would
search packages in my .R/library
directory, where R would find both my packages
and the links for the CRAN packages.
How can I change the deafault searching
path for the packages? (I know
I can always do library(xxx, lib.loc="/home/alobo/.R/library"),
but it would be nicer having this as default).

Thanks

Agus

Dr. Agustin Lobo
Instituto de Ciencias de la Tierra (CSIC)
Lluis Sole Sabaris s/n
08028 Barcelona SPAIN
tel 34 93409 5410
fax 34 93411 0012
alobo at ija.csic.es


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
> Well, thanks to you all
  > I've been able to install my first
  > little package. I've dumped
  > some of my Splus(PC) functions
  > to an ascii file (*.R), created
  > the directory structure and the
  > DESCRIPTION and INDEX files. Then
  > I checked and installed with:

  > R CMD INSTALL -l ~/.R/library Sutilpangea

This is not a good idea, because the .R directory is a *temporary*
directory that R uses (on unix), and basically is created newly every
time you do help.start(), so your package will get deleted if you
install it there.

A typical place for private packages would be $HOME/lib/R but of
course you're free to use any place you like (except .R :-)


  > because I found that I have an .R directory
  > in my home where a subdirectory .R/library
  > has links to where the packages really are
  > (/usr/lib/R/library). Therefore, I decided
  > to keep  my own packages in .R/library
  > while the CRAN packages really stay in
  > /usr/lib/R/library.

  > Now the only problem is that, by default, R
  > searches packages in /usr/lib/R/library
  > because of the value of R_HOME:

  >> system ("echo $R_HOME")
  > /usr/lib/R

  > It would be better if R would
  > search packages in my .R/library
  > directory, where R would find both my packages
  > and the links for the CRAN packages.
  > How can I change the deafault searching
  > path for the packages? (I know
  > I can always do library(xxx, lib.loc="/home/alobo/.R/library"),
  > but it would be nicer having this as default).

One possible way to solve this problem: R searches all libraries in
the environment variable R_LIBS, please read the documentation.

Hope this helps,