[R-SIG-Mac] accented vowels

Denis Chabot chabotd at globetrotter.net
Tue Aug 16 14:07:18 CEST 2011


Duncan, I think I'll avoid the problem in another manner, leaving me free to choose whatever file names I want or need.

The reason I used gsub on file names is that I want to collate a series of data.frames using rbind (or rbind.fill). For this, I need to know the names of the data.frames I just read and this depends on the files that were in the directory I choose to read.

I therefore use a bunch of gsub to extract data.frame names from file names (file names were constructed to make this possible).

But I did this only because I did not know how to find the name of a data.frame after it is loaded. I searched on the net to see if this was feasible. I did not find a way to do this (short of doing a ls() before and after each load to see what has changed) but I found something close, thanks to you actually, in an answer you gave to another user!

> Aug 12, 2011; 3:23pmRe: Getting data from an *.RData file into a data.frame object.
> 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.
> ... [show rest of quote]
> 
> 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 

I'll use this in the current project to avoid the situation that led to my initial message. Many thanks!

Denis


More information about the R-SIG-Mac mailing list