I'd like to use a string to refer to an R object with the end objective of going through a loop and saving various files of the same name with different contents using a numbered suffix. # This will be the loop counter and file suffix. master.i <- 1 # This is the generic file name. unislopes <- c(1,2,3) # This assigns the data to the correct file name "unislopes1". assign(paste("unislopes",master.i,sep=""),unislopes) # This is the problem. The first parameter of the "save" function requires an R object which I'm not sure how to reference using the suffix "1". The second part requires text so it can use the paste function. save((paste("unislopes",master.i,sep=""),file=paste("unislopes",master.i,".Rdata",sep="")) Any ideas? -- Best regards, David Young Marketing and Statistical Consultant Madrid, Spain +34 913 540 381 http://www.linkedin.com/in/europedavidyoung mailto:dyoung at telefonica.net
save(list=paste("unislopes", master.i, sep=""), file=paste("unislopes",master.i,".Rdata",sep="")) On Mon, Apr 12, 2010 at 12:06 PM, David Young <dyoung at telefonica.net> wrote:> I'd like to use a string to refer to an R object with the end > objective of going through a loop and saving various files of the same > name with different contents using a numbered suffix. > > # This will be the loop counter and file suffix. > master.i <- 1 > > # This is the generic file name. > unislopes <- c(1,2,3) > > # This assigns the data to the correct file name "unislopes1". > assign(paste("unislopes",master.i,sep=""),unislopes) > > # This is the problem. ?The first parameter of the "save" function > requires an R object which I'm not sure how to reference using the > suffix "1". ?The second part requires text so it can use the > paste function. > save((paste("unislopes",master.i,sep=""),file=paste("unislopes",master.i,".Rdata",sep="")) > > Any ideas? > > > > > > -- > Best regards, > > David Young > Marketing and Statistical Consultant > Madrid, Spain > +34 913 540 381 > http://www.linkedin.com/in/europedavidyoung > > ? ? ? ? ? ? ? ? ? ? ? ? ?mailto:dyoung at telefonica.net > > ______________________________________________ > 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. >
?get On 2010-04-12 5:06, David Young wrote:> I'd like to use a string to refer to an R object with the end > objective of going through a loop and saving various files of the same > name with different contents using a numbered suffix. > > # This will be the loop counter and file suffix. > master.i<- 1 > > # This is the generic file name. > unislopes<- c(1,2,3) > > # This assigns the data to the correct file name "unislopes1". > assign(paste("unislopes",master.i,sep=""),unislopes) > > # This is the problem. The first parameter of the "save" function > requires an R object which I'm not sure how to reference using the > suffix "1". The second part requires text so it can use the > paste function. > save((paste("unislopes",master.i,sep=""),file=paste("unislopes",master.i,".Rdata",sep="")) > > Any ideas? > > > > >-- Peter Ehlers University of Calgary