Hi, I'm slowly migrating from SAS to R and - for the very first time - I'm working with a native .Rda data file (rather than importing data from other sources). When I load this .Rda file into the global environment using load("file path") I see a data.frame in the global environment called "mydata" that corresponds to the .rda file. My question: how can I change the name of this data.frame to something of my choosing? Thanks for considering this very simple question. Leslie [[alternative HTML version deleted]]
I think that the .rda extension is the old extension convention for what now gets the .RData extension name by convention. These are basically workspaces. These .RData files can contain multiple data objects, and all objects seem to read back in with the same name that they were saved with using the save() function. Of course, you can assign a new name to the objects you read in with the standard <- or -> syntax. See ?save, to lean how to save them with the new name. You can save just an individual data object in an .rda or .RData file and make the data object name match the filename if you so wish. On 8/30/2016 9:37 AM, Leslie Rutkowski wrote:> Hi, > > I'm slowly migrating from SAS to R and - for the very first time - I'm > working with a native .Rda data file (rather than importing data from other > sources). When I load this .Rda file into the global environment using > load("file path") I see a data.frame in the global environment called > "mydata" that corresponds to the .rda file. > > My question: how can I change the name of this data.frame to something of > my choosing? > > Thanks for considering this very simple question. > > Leslie > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.-- -- Robert W. Baer, Ph.D. Professor of Physiology Kirksville College of Osteopathic Medicine A T Still University of Health Sciences 800 W. Jefferson St Kirksville, MO 63501 660-626-2321 Department 660-626-2965 FAX
You cannot. However, you can load the file into a dedicated environment to keep those names separated from your global environment. e.g. [1] The saveRDS/loadRDS functions are an alternative handle one object at a time without dragging the object names into the picture (you have to name the re-loaded object). However, the best approach is to write scripts that pull directly from your source (non-R) data files. This makes your work process reproducible as you develop it. [1] https://stat.ethz.ch/pipermail/r-help/2016-August/441078.html -- Sent from my phone. Please excuse my brevity. On August 30, 2016 7:37:24 AM PDT, Leslie Rutkowski <leslie.rutkowski at gmail.com> wrote:>Hi, > >I'm slowly migrating from SAS to R and - for the very first time - I'm >working with a native .Rda data file (rather than importing data from >other >sources). When I load this .Rda file into the global environment using >load("file path") I see a data.frame in the global environment called >"mydata" that corresponds to the .rda file. > >My question: how can I change the name of this data.frame to something >of >my choosing? > >Thanks for considering this very simple question. > >Leslie > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >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.
>>>>> Jeff Newmiller <jdnewmil at dcn.davis.ca.us> >>>>> on Tue, 30 Aug 2016 09:36:05 -0700 writes:> You cannot. However, you can load the file into a dedicated environment to keep those names separated from your global environment. e.g. [1] yes, that's my "famous" only-allowed use of attach() : attach() an rda-file to your search patch instead of polluting your globalenv. > The saveRDS / loadRDS saveRDS / readRDS are the correct names > functions are an alternative handle one object at a time without dragging the object names into the picture (you have to name the re-loaded object). The fact that it is readRDS() and not loadRDS(), actually does convey via it is often "much better" in the sense of functional / transparent programming to use this pair in favor of save() / load() : readRDS() does *return* what we are interested in, and result <- readRDS(<file>) is so much better than load(<file>) silently overwriting all kinds of objects in my globalenv. Indeed, I strongly advocate to use saveRDS() and readRDS() much more frequently than they are used nowawadays. > However, the best approach is to write scripts that pull directly from your source (non-R) data files. This makes your work process reproducible as you develop it. Yes, but that's sometimes too inefficient. And then, some of us do simulations and other expensive computations, we need/want to save and re-read. and yes, I *always* use the equivalent of q("no") to leave R; never save the workspace or load it at startup, unless accidentally on non-standard (for me) platforms. Martin > [1] https://stat.ethz.ch/pipermail/r-help/2016-August/441078.html > -- > Sent from my phone. Please excuse my brevity. > On August 30, 2016 7:37:24 AM PDT, Leslie Rutkowski <leslie.rutkowski at gmail.com> wrote: >> Hi, >> >> I'm slowly migrating from SAS to R and - for the very first time - I'm >> working with a native .Rda data file (rather than importing data from >> other >> sources). When I load this .Rda file into the global environment using >> load("file path") I see a data.frame in the global environment called >> "mydata" that corresponds to the .rda file. >> >> My question: how can I change the name of this data.frame to something >> of >> my choosing? >> >> Thanks for considering this very simple question. >> >> Leslie >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.