I have a data frame 'tmp' and a vector 'name' containing 'd2'. I want to save 'tmp' under the name hidden in 'name', and the file must have the same name, plus the extension '.rda'. So I try> tmpx y 1 1 3 2 2 4> name[1] "d2"> assign(name, tmp) > summary(get(name))x y Min. :1.00 Min. :3.00 1st Qu.:1.25 1st Qu.:3.25 Median :1.50 Median :3.50 Mean :1.50 Mean :3.50 3rd Qu.:1.75 3rd Qu.:3.75 Max. :2.00 Max. :4.00> save(get(name), file = paste(name, "rda", sep = "."))Error in save(get(name), file = paste(name, "rda", sep = ".")) : object ‘get(name)’ not found ++++++++++++++++++++++ I can't figure out where I 'get' it wrong. In real life I have a bunch of text files named like 'd1.txt', ..., 'd100.txt'. I want to convert all of them to R data files, with one data frame in each named d1, ..., d100. Any suggestion is much appreciated! -- Göran Broström [[alternative HTML version deleted]]
Hi! Why don't you just save tmp? save(tmp, file = paste(name, "rda", sep = ".")) I don't think it makes much difference, at least not with your example. Or does it? Ivan Le 9/9/2011 11:55, G?ran Brostr?m a ?crit :> I have a data frame 'tmp' and a vector 'name' containing 'd2'. > I want to save 'tmp' under the name hidden in 'name', and the file must have > the same name, plus the extension '.rda'. > So I try > >> tmp > x y > 1 1 3 > 2 2 4 >> name > [1] "d2" >> assign(name, tmp) >> summary(get(name)) > x y > Min. :1.00 Min. :3.00 > 1st Qu.:1.25 1st Qu.:3.25 > Median :1.50 Median :3.50 > Mean :1.50 Mean :3.50 > 3rd Qu.:1.75 3rd Qu.:3.75 > Max. :2.00 Max. :4.00 >> save(get(name), file = paste(name, "rda", sep = ".")) > Error in save(get(name), file = paste(name, "rda", sep = ".")) : > object ???get(name)??? not found > ++++++++++++++++++++++ > I can't figure out where I 'get' it wrong. > > In real life I have a bunch of text files named like 'd1.txt', ..., > 'd100.txt'. > I want to convert all of them to R data files, with one data frame in each > named d1, ..., d100. > > Any suggestion is much appreciated! > > > ______________________________________________ > R-help at 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.calandra at uni-hamburg.de ********** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php
On 11-09-09 5:55 AM, G?ran Brostr?m wrote:> I have a data frame 'tmp' and a vector 'name' containing 'd2'. > I want to save 'tmp' under the name hidden in 'name', and the file must have > the same name, plus the extension '.rda'. > So I try > >> tmp > x y > 1 1 3 > 2 2 4 >> name > [1] "d2" >> assign(name, tmp) >> summary(get(name)) > x y > Min. :1.00 Min. :3.00 > 1st Qu.:1.25 1st Qu.:3.25 > Median :1.50 Median :3.50 > Mean :1.50 Mean :3.50 > 3rd Qu.:1.75 3rd Qu.:3.75 > Max. :2.00 Max. :4.00 >> save(get(name), file = paste(name, "rda", sep = ".")) > Error in save(get(name), file = paste(name, "rda", sep = ".")) : > object ???get(name)??? not found > ++++++++++++++++++++++ > I can't figure out where I 'get' it wrong.save() does funny things with its arguments: the first one is not evaluated in the standard way. It wants a name or a character string. So you would want to pass name instead of get(name), but that would end up being interpreted the wrong way and you'd just save the name variable, not the thing it refers to. You will probably have to use do.call to do this, i.e. do.call(save, list(name, file=paste(name, "rda", sep = "."))) This will evaluate the name before passing it to save(). Duncan Murdoch> > In real life I have a bunch of text files named like 'd1.txt', ..., > 'd100.txt'. > I want to convert all of them to R data files, with one data frame in each > named d1, ..., d100. > > Any suggestion is much appreciated! > > > > ______________________________________________ > R-help at 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.