Skip to content

Transferring data from S+ to R

4 messages · Brian Ripley, Jeffrey A. Royle, Zivan Karaman

#
I would like to know if there is an easy way to transfer all the data from
a S+ directory (".Data" or "_data") to an R image? I would like to transfer
all the functions and all the data sets (data frames, vectors, lists, etc.).

I'm working under Windows NT and am using S+ 3.3 for Windows.

Zivan


Zivan Karaman
Limagrain Genetics Research, B.P. 115, 63203 Riom Cedex, France
Tel: +33 (0) 473 634 343     Fax: +33 (0) 473 634 345
E-mail: zivan.karaman at biocem.univ-bpclermont.fr
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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 Thu, 14 Jan 1999, Zivan Karaman wrote:

            
R version? I'll assume rw0631.

You could try

In S-PLUS

dump(ls(), "dirdump", T)

in R (having set a large enough workspace)

source("dirdump")
save.image()

This is not guaranteed to work: R is not S and for example S objects can
have storage modes not supported in R, and the functions may not be valid
R, but it will give you a start and you can edit the file dirdump to
change such things, as it will be a text file in the S language.

Remember that source will not work unless the file is entirely correct:
you may see more of what is going on by using rterm and a batch file
(details in the V&R R complements).

The same ideas work for the reverse transfer: in R you need

dump(ls(all.names=T), "dirdump")

but if the help page is up-to-date `the implementation of dump is very
incomplete'.
#
I use the brute force method: 

S> dump(ls()) 

R> source("dumpdata")

can't imagine something much easier.
On Thu, 14 Jan 1999, Zivan Karaman wrote:

            
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Thanks to everyone for helpful suggestions.

I followed the proposed method, and besides the expected trouble (objects
of user-defined classes, and special objects as .Random.seed, last.warning,
last.dump, and .Last.value) the only other problem I run into was with "lm"
objects that were produced with the needed data frame attached, rather than
by providing it in "data" argument of "lm" function (probably bad practice
anyway).

As a result of the experience, I've created the following function:

"export" <-
function(file = "s2r", classes = c("function", "data.frame", "list",
"matrix", "numeric", "character", "logical"))
{
	x <- row.names(objects.summary(data.class = classes))
	i <- match(c("last.dump", "last.warning", ".Last.fixed", ".Last.value",
".Random.seed"), x)
	i <- i[!is.na(i)]
	if(length(i) > 0)
		x <- x[ - i]
	dump(x, fileout = file)
}

It is self-explanatory; just note that providing NULL as the value for the
"classes" argument will give you all the objects, regardless of their
data.class. 

It has been used (I don't dare say tested) with S+ 3.3 and rw0631 only (and
with NT 4.0).

The method works for reasonably sized data: I was unable to transfer a 1000
x 500 matrix, since R ran out of memory (even with --nsize 1000000).

Thanks again.

Zivan

Zivan Karaman
Limagrain Genetics Research, B.P. 115, 63203 Riom Cedex, France
Tel: +33 (0) 473 634 343     Fax: +33 (0) 473 634 345
E-mail: zivan.karaman at biocem.univ-bpclermont.fr
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._