[R] Import problem with S-Plus 7.0 dataset

Inman, Brant A. M.D. Inman.Brant at mayo.edu
Fri Nov 3 22:39:30 CET 2006


Thanks to Brian Ripley and Richard Heiberger for the solution to my
problem.  I will spell it out below in steps so that (hopefully) nobody
else will need to ask the same question in the future (if they search
the R help archive).

HOW TO GET S-PLUS 7.0 DATA into R
__________________________________

STEP 0  (in S-Plus 7.0): Generation of a fake dataframe:

> x <- c(1:10)
> y <- rep(c(0,1),5)
> mydata <- data.frame(cbind(x,y))
> mydata
    x y
1   1 0
2   2 1
3   3 0
4   4 1
5   5 0
6   6 1
7   7 0
8   8 1
9   9 0
10 10 1

STEP 1 (in S-Plus 7.0): Save the dataframe as earlier versions of S-Plus
did
(note: I called the output file "ddump.sdd" instead of "mydata.sdd" to
demonstrate a point later on)

>data.dump('mydata', file='C:\\temp\\ddump.sdd', oldStyle=T)

STEP 2 (In R): Restore the saved dataframe

>data.restore('C:\\temp\\ddump.sdd')
[1] "C:\\temp\\ddump.sdd"

STEP 3 (In R): View/use the first few cases of dataset)

> head(mydata)
  x y
1 1 0
2 2 1
3 3 0
4 4 1
5 5 0
6 6 1


There are 2 important points to note:
1) The dataframe keeps the name it had in S-Plus, not the name of the
file you saved it in. Using the example above, R never creates an object
called "ddump":

> data.restore('C:\\temp\\ddump.sdd')
[1] "C:\\temp\\ddump.sdd"
> ddump
Error: object "ddump" not found

2) Saving the data.restore result into a new variable is not that useful
because it will NOT contain your dataframe, only the name of the file
that contained your dataframe:

>test <- data.restore('C:\\temp\\ddump.sdd')
>test
[1] "C:\\temp\\ddump.sdd"


Brant Inman



-----Original Message-----
From: Richard M. Heiberger [mailto:rmh at temple.edu] 
Sent: Friday, November 03, 2006 3:07 PM
To: Inman, Brant A. M.D.; Brian Ripley
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Import problem with S-Plus 7.0 dataset

It looks like it works.  The result you printed is
the name of the file that data.store read.  The name of the
variable is the same as the name you called it in S-Plus.

type
   data[1:5,]
and you should see your data.frame.



More information about the R-help mailing list