From Kurt.Hornik@ci.tuwien.ac.at  Wed Dec 17 17:46:42 1997
From: Kurt.Hornik@ci.tuwien.ac.at (Kurt Hornik)
Date: Wed, 17 Dec 1997 18:46:42 +0100
Subject: library/data
In-Reply-To: <97Dec17.110640est.26756@mailgate.bank-banque-canada.ca>
References: <97Dec17.110640est.26756@mailgate.bank-banque-canada.ca>
Message-ID: <199712171746.SAA04913@pc25.none>

>>>>> Paul Gilbert writes:

> I have some data files with my library which are used for examples and
> testing the code. To date I have kept them in a subdirectory I called
> ../dse/dsedata, but I am trying to move those to .../dse/data as
> perscribed for installing libraries. However, these datasets are not
> all R object, some are just files that I source from within a
> function, and one is accessed by a separate process that I call from
> R.

Official R speak actually is `package' for what you call `library'.

> 1/ Should the data subdirectory be reserved for R objects?

No.  You can have data of any kind ther.  However, currently data() only
works for R objects, i.e., files with R code and names ending in `.R'.
Within soon, this should be extended so that e.g. `.tab' is using for
tables (and we still have to determine how to treat headers ...).

> 2/ Could someone explain or point me to were I can find the
> explanation of how R objects in this data subdirectory should be
> constructed? Are these objects automatically loaded when a library is
> loaded?

No, they are not loaded automatically.  Currently, there is (still) no
way to attach a directory.  This will change eventually.

If you build a package for use with R and there is no reason to store
data in a specific format, you might as well try to dump() your object
and put the result of that into the data dir of the pkg (thus you'd have
sourceable R code etc.)  If you want to distribute something in some
other format, e.g. `file.of', then `file.R' should contain the R code
for reading the contents of `file.of' into R.

> 3/ To date I have been able to find my subdirectory by setting a
> variable indicating its location in the library file from which code
> is loaded.  Admittedly this was a kludge, but I could do it because I
> had my own make which embedded the location in the file when it was
> installed. I was not very happy with this trick, but it seems I
> completely lose this ability using R INSTALL.  >> From within R is
> there a good way to find the location of a library when it is loaded
> or after it is loaded?

Not quite.  There is a function called system.file() which does
something similar:

R> system.file("R/base")
[1] "/usr/local/lib/R/library/base/R/base"
R> system.file("data/index.doc")
[1] "/usr/local/lib/R/library/base/data/index.doc"
> system.file("*/index.doc")
[1] "/usr/local/lib/R/library/base/data/index.doc"

Would it be important to know the location of a package?

-k
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


library/data
Kurt Hornik