I am running R 2.3.1 on a Windows XP machine. I am trying to import some data into R that is stored as an S-Plus 7.0 .sdd file. When I run the following command, I get this error:> library(foreign) > d <- read.S(file='H:\\Research\\data.sdd')Error in read.S(file = "H:\\Research\\data.sdd") : not an S object The dataset is fairly large, roughly 13000 rows and 100 columns, but within S-Plus 7.0 it is stored as a normal dataframe (not a bd dataframe). Any ideas? Brant Inman [[alternative HTML version deleted]]
>From ?read.S'read.S' can read the binary files produced in most recent versions of S-PLUS on either Windows (versions 3.x, 4.x, 2000) or Unix (version 3.x with 4 byte integers). It automatically detects whether the file was produced on a big- or little-endian machine and adapts itself accordingly. 'data.restore' can read a similar range of files produced by 'data.dump', for newer versions of S-PLUS, those from 'data.dump(....., oldStyle=TRUE)'. Note: not S-PLUS 7.0. You need to dump with 'data.dump(....., oldStyle=TRUE)' to have a chance of reading it. On Fri, 3 Nov 2006, Inman, Brant A. M.D. wrote:> > I am running R 2.3.1 on a Windows XP machine. I am trying to import > some data into R that is stored as an S-Plus 7.0 .sdd file. > > When I run the following command, I get this error: > >> library(foreign) >> d <- read.S(file='H:\\Research\\data.sdd') > > Error in read.S(file = "H:\\Research\\data.sdd") : > not an S object > > > The dataset is fairly large, roughly 13000 rows and 100 columns, but > within S-Plus 7.0 it is stored as a normal dataframe (not a bd > dataframe). > > Any ideas? > > Brant Inman > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
read.S is used to read S3 files (S-Plus 4 and older, not S-Plus 6 or newer) from the binary in the _Data directory. For example y <- read.S("c:/HOME/rmh/503.f99/_Data/y") data.restore is used to read S3 .sdd data.dump files. The S3 part means that S-Plus 7 users must force the oldStyle data.dump. ## S-Plus 7 data.dump("y", oldStyle=TRUE) ## R data.restore("c:/HOME/hh-user/dumpdata")
As recommended, I have tried the following code to solve my problem importing data to R from S-Plus 7.0. Unfortunately, I have not had success. In S-Plus:> data.dump('data', file='C:\\temp\\ddump.sdd', oldStyle=T)This resulted in the production of a file called "ddump.sdd" that I can import into S-Plus without any problem. However, when I use the following code in R ... In R:> d <- data.restore(file='C:\\temp\\ddump.sdd') > d[1] "C:\\temp\\ddump.sdd"> d <- data.restore('C:\\temp\\ddump.sdd') > d[1] "C:\\temp\\ddump.sdd">I also tried the following:> d <- read.S(file='C:\\temp\\ddump.sdd')Error in read.S(file = "C:\\temp\\ddump.sdd") : not an S object I thought that S-Plus might be doing something funny when I save as a .sdd file, so I tried saving as "ddump.dat" but got exactly the same results. I have been able to save my original datafile as a csv and import it, but I had hoped that it would be possible to keep my variable formats by importing the S dataframe into R directly. Brant Inman [[alternative HTML version deleted]]
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.
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)) > mydatax 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"> ddumpError: 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.
Tony Plate
2006-Nov-21 16:57 UTC
[Rd] Documentation error for data.restore() in package "foreign" (was Re: [R] Import problem with S-Plus 7.0 dataset)
BTW, the help file for data.restore says: Value: an R version of the S3 object. It looks like this may need correction (when I try this function out, it returns the file name, not the object restored from the file.) I tried this in R 2.4.0: > sessionInfo() R version 2.4.0 (2006-10-03) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] "methods" "stats" "graphics" "grDevices" "utils" "datasets" [7] "base" other attached packages: foreign ncdf "0.8-17" "1.6" > -- Tony Plate (redirected from an old thread on R-help -- I was waiting until I had R 2.4.0 installed so that I could verify that this was still a problem. Apologies if it has been fixed since then) Richard M. Heiberger wrote:> 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. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >