Re: [R] Getting data from an *.RData file into a data.frame object.

2011-08-15 Thread Ivan Calandra
I like using saveObject() and loadObject() from package R.utils because 
you can assign the data to a new object.


Like this:
library(R.utils)
saveObject(df, file="file.Rbin")
df2 <- loadObject("file.Rbin")

HTH,
Ivan

Le 8/12/2011 21:38, peter dalgaard a écrit :

On Aug 12, 2011, at 21:12 , Ed Heaton wrote:


Hi, all.

I'm new to R.  I've been a SAS programmer for 20 years.

I seem to be having trouble with the most basic task - bringing a table in
an *.RData file into a data.frame object.

Here's how I created the *.RData file.

library(RODBC)
db<- odbcConnect("***")
df<- sqlQuery(
db
  , "select * from schema.table where year(someDate)=2006"
)
save(
df
  , file="C:/Documents and Settings/userName/My Documents/table2006.RData"
)
dim(df)
remove(df)
odbcClose(db)
remove(db)
detach("package:RODBC")

Next, I moved that data file (table2006.RData) to another workstation - not
at the client site.

Now, I need to get that data file into a data.frame object.  I know this
should be simple, but I can't seem to find out how to do that.  I tried the
following.  First, after opening R without doing anything, RGui used 35,008
KB of memory.  I submitted the following.


debt2006<- load("T:/R.Data/table2006.RData")

Memory used by RGui jumped to 191,512 KB.  So, it looks like the data
loaded.  However, debt2005 is of type character instead of data.frame.


ls()

[1] "debt2005"

class(debt2005)

[1] "character"
Help, please.


The load/save mechanism handles multiple objects. You can't really assign the result of 
load(), its return value is just a vector of object names ("df", right?).

So look in your workspace for an object called "df". Then assign it to 
debt2005. AFAIK, this won't duplicate quite as much as it sounds it might.

For a single-step variation, try something like

debt2005<- local({load(myfile); df})



Ed

Ed Heaton
Project Manager, Sr. SAS Developer
Data and Analytic Solutions, Inc.
10318 Yearling Drive
Rockville, MD 20850
Office: 301-520-7414
ehea...@dasconsultants.com
www.dasconsultants.com
CMMI ML-2, SBA 8(a)&  SDB, WBE (WBENC), MBE (VA&  MD)

e...@heaton.name

(Re: http://www.r-project.org/posting-guide.html)

__
R-help@r-project.org 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.


--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Dept. Mammalogy
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php

__
R-help@r-project.org 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.


Re: [R] Getting data from an *.RData file into a data.frame object.

2011-08-12 Thread peter dalgaard

On Aug 12, 2011, at 21:12 , Ed Heaton wrote:

> Hi, all.
> 
> I'm new to R.  I've been a SAS programmer for 20 years.
> 
> I seem to be having trouble with the most basic task - bringing a table in
> an *.RData file into a data.frame object.
> 
> Here's how I created the *.RData file.
> 
> library(RODBC)
> db <- odbcConnect("***")
> df <- sqlQuery(
>db
>  , "select * from schema.table where year(someDate)=2006"
> )
> save(
>df
>  , file="C:/Documents and Settings/userName/My Documents/table2006.RData"
> )
> dim(df)
> remove(df)
> odbcClose(db)
> remove(db)
> detach("package:RODBC")
> 
> Next, I moved that data file (table2006.RData) to another workstation - not
> at the client site.
> 
> Now, I need to get that data file into a data.frame object.  I know this
> should be simple, but I can't seem to find out how to do that.  I tried the
> following.  First, after opening R without doing anything, RGui used 35,008
> KB of memory.  I submitted the following.
> 
>> debt2006 <- load("T:/R.Data/table2006.RData")
> 
> Memory used by RGui jumped to 191,512 KB.  So, it looks like the data
> loaded.  However, debt2005 is of type character instead of data.frame.
> 
>> ls()
> [1] "debt2005"
>> class(debt2005)
> [1] "character"
>> 
> 
> Help, please.
> 

The load/save mechanism handles multiple objects. You can't really assign the 
result of load(), its return value is just a vector of object names ("df", 
right?).

So look in your workspace for an object called "df". Then assign it to 
debt2005. AFAIK, this won't duplicate quite as much as it sounds it might.

For a single-step variation, try something like

debt2005 <- local({load(myfile); df})


> Ed
> 
> Ed Heaton
> Project Manager, Sr. SAS Developer
> Data and Analytic Solutions, Inc.
> 10318 Yearling Drive
> Rockville, MD 20850
> Office: 301-520-7414
> ehea...@dasconsultants.com
> www.dasconsultants.com  
> CMMI ML-2, SBA 8(a) & SDB, WBE (WBENC), MBE (VA & MD)
> 
> e...@heaton.name
> 
> (Re: http://www.r-project.org/posting-guide.html)
> 
> __
> R-help@r-project.org 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com
"Døden skal tape!" --- Nordahl Grieg

__
R-help@r-project.org 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.


Re: [R] Getting data from an *.RData file into a data.frame object.

2011-08-12 Thread Duncan Murdoch

On 12/08/2011 3:12 PM, Ed Heaton wrote:

Hi, all.

I'm new to R.  I've been a SAS programmer for 20 years.

I seem to be having trouble with the most basic task - bringing a table in
an *.RData file into a data.frame object.

Here's how I created the *.RData file.

library(RODBC)
db<- odbcConnect("***")
df<- sqlQuery(
 db
   , "select * from schema.table where year(someDate)=2006"
)
save(
 df
   , file="C:/Documents and Settings/userName/My Documents/table2006.RData"
)
dim(df)
remove(df)
odbcClose(db)
remove(db)
detach("package:RODBC")

Next, I moved that data file (table2006.RData) to another workstation - not
at the client site.

Now, I need to get that data file into a data.frame object.  I know this
should be simple, but I can't seem to find out how to do that.  I tried the
following.  First, after opening R without doing anything, RGui used 35,008
KB of memory.  I submitted the following.

>  debt2006<- load("T:/R.Data/table2006.RData")

Memory used by RGui jumped to 191,512 KB.  So, it looks like the data
loaded.  However, debt2005 is of type character instead of data.frame.

>  ls()
[1] "debt2005"
>  class(debt2005)
[1] "character"
>

Help, please.


save() and load() work with multiple objects, and the objects keep their 
names.  So your object would be recreated as "df" after the load.


If you just want to save the data from one object without its name, use 
saveRDS() and readRDS().


Duncan Murdoch

__
R-help@r-project.org 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.


[R] Getting data from an *.RData file into a data.frame object.

2011-08-12 Thread Ed Heaton
Hi, all.

I'm new to R.  I've been a SAS programmer for 20 years.

I seem to be having trouble with the most basic task - bringing a table in
an *.RData file into a data.frame object.

Here's how I created the *.RData file.

library(RODBC)
db <- odbcConnect("***")
df <- sqlQuery(
db
  , "select * from schema.table where year(someDate)=2006"
)
save(
df
  , file="C:/Documents and Settings/userName/My Documents/table2006.RData"
)
dim(df)
remove(df)
odbcClose(db)
remove(db)
detach("package:RODBC")

Next, I moved that data file (table2006.RData) to another workstation - not
at the client site.

Now, I need to get that data file into a data.frame object.  I know this
should be simple, but I can't seem to find out how to do that.  I tried the
following.  First, after opening R without doing anything, RGui used 35,008
KB of memory.  I submitted the following.

> debt2006 <- load("T:/R.Data/table2006.RData")

Memory used by RGui jumped to 191,512 KB.  So, it looks like the data
loaded.  However, debt2005 is of type character instead of data.frame.

> ls()
[1] "debt2005"
> class(debt2005)
[1] "character"
>

Help, please.

Ed

Ed Heaton
Project Manager, Sr. SAS Developer
Data and Analytic Solutions, Inc.
10318 Yearling Drive
Rockville, MD 20850
Office: 301-520-7414
ehea...@dasconsultants.com
www.dasconsultants.com  
CMMI ML-2, SBA 8(a) & SDB, WBE (WBENC), MBE (VA & MD)

e...@heaton.name

(Re: http://www.r-project.org/posting-guide.html)

__
R-help@r-project.org 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.