pierz
2011-Mar-17 15:05 UTC
[R] Beginner question: How to replace part of a filename in read.csv?
I would like to use samp as a part of a filename that I can change. My source files are .csv files with date as the file name, and I would like to be able to type in the date (later perhaps automate this using list.files) and then read the csv and write the pdf automatically. I have tried different combinations with "" and () around samp, but I keep getting the error "object 'samp.csv' not found". samp <- "20110317" read.csv(file=samp.csv,...) #next R processes some code that works fine, and then should save the figure: pdf(file=samp.pdf,...) dev.off() How can I get R to replace samp as 20110317 in front of .csv and .pdf? Best, Sjouke -- View this message in context: http://r.789695.n4.nabble.com/Beginner-question-How-to-replace-part-of-a-filename-in-read-csv-tp3384786p3384786.html Sent from the R help mailing list archive at Nabble.com.
Scott Chamberlain
2011-Mar-17 17:33 UTC
[R] Beginner question: How to replace part of a filename in read.csv?
> paste(samp, ".pdf", sep="")[1] "20110317.pdf"> paste(samp, ".csv", sep="")[1] "20110317.csv" On Thursday, March 17, 2011 at 10:05 AM, pierz wrote: I would like to use samp as a part of a filename that I can change. My source> files are .csv files with date as the file name, and I would like to be able > to type in the date (later perhaps automate this using list.files) and then > read the csv and write the pdf automatically. I have tried different > combinations with "" and () around samp, but I keep getting the error > "object 'samp.csv' not found". > > samp <- "20110317" > read.csv(file=samp.csv,...) > #next R processes some code that works fine, and then should save the > figure: > pdf(file=samp.pdf,...) > dev.off() > > How can I get R to replace samp as 20110317 in front of .csv and .pdf? > > Best, > Sjouke > > -- > View this message in context: http://r.789695.n4.nabble.com/Beginner-question-How-to-replace-part-of-a-filename-in-read-csv-tp3384786p3384786.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
Sarah Goslee
2011-Mar-17 17:38 UTC
[R] Beginner question: How to replace part of a filename in read.csv?
You need to use paste(), as in paste(samp, ".csv", sep="") Use that as your filename. Sarah On Thu, Mar 17, 2011 at 11:05 AM, pierz <s.piersma at gmail.com> wrote:> I would like to use samp as a part of a filename that I can change. My source > files are .csv files with date as the file name, and I would like to be able > to type in the date (later perhaps automate this using list.files) and then > read the csv and write the pdf automatically. I have tried different > combinations with "" and () around samp, but I keep getting the error > "object 'samp.csv' not found". > > samp <- "20110317" > read.csv(file=samp.csv,...) > #next R processes some code that works fine, and then should save the > figure: > pdf(file=samp.pdf,...) > dev.off() > > How can I get R to replace samp as 20110317 in front of .csv and .pdf? > > Best, > Sjouke >-- Sarah Goslee http://www.functionaldiversity.org
pierz
2011-Mar-18 09:43 UTC
[R] Beginner question: How to replace part of a filename in read.csv?
Thank you both, it works! -- View this message in context: http://r.789695.n4.nabble.com/Beginner-question-How-to-replace-part-of-a-filename-in-read-csv-tp3384786p3386724.html Sent from the R help mailing list archive at Nabble.com.