Greetings all, I would like to append a 4 digit number suffix to the names of my files for later use. What I am using now only produces 1 or 2 or 3 or 4 digits. ############ for (i in 1:1000) { temp <- (kegg [i,]) temp <- merge (temp, subrichcdt, by="gene") file.name <- paste ("kegg.subrichcdt.", i, ".txt", sep="") write.table(temp, file=file.name) } ####### But I want: "kegg.subrichcdt.0001.txt" "kegg.subrichcdt.0002.txt", ... Any suggestions M -- Matt Curcio M: 401-316-5358 E: matt.curcio.ri at gmail.com
R. Michael Weylandt <michael.weylandt@gmail.com>
2011-Jul-31 17:46 UTC
[R] Appending 4 Digits On A File Name
I think this will do it: formatC(i,width=4,format="d",flag="0") Michael Weylandt On Sun, Jul 31, 2011 at 12:30 PM, Matt Curcio <matt.curcio.ri@gmail.com>wrote:> Greetings all, > I would like to append a 4 digit number suffix to the names of my > files for later use. What I am using now only produces 1 or 2 or 3 or > 4 digits. > > ############ > for (i in 1:1000) { > temp <- (kegg [i,]) > temp <- merge (temp, subrichcdt, by="gene") > file.name <- paste ("kegg.subrichcdt.", i, ".txt", sep="") > write.table(temp, file=file.name) > } > ####### > But I want: > "kegg.subrichcdt.0001.txt" > "kegg.subrichcdt.0002.txt", ... > > > Any suggestions > M > -- > > > Matt Curcio > M: 401-316-5358 > E: matt.curcio.ri@gmail.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]]
See ?sprintf (and/or search the web for sprintf), e.g. filename <- sprintf("kegg.subrichcdt.%04d.txt", i) /Henrik On Sun, Jul 31, 2011 at 10:30 AM, Matt Curcio <matt.curcio.ri at gmail.com> wrote:> Greetings all, > I would like to append a 4 digit number suffix to the names of my > files for later use. ?What I am using now only produces 1 or 2 or 3 or > 4 digits. > > ############ > for (i in 1:1000) { > ? temp <- (kegg [i,]) > ? temp <- merge (temp, subrichcdt, by="gene") > ? ? ?file.name <- paste ("kegg.subrichcdt.", i, ".txt", sep="") > ? ? ?write.table(temp, file=file.name) > } > ####### > But I want: > "kegg.subrichcdt.0001.txt" > "kegg.subrichcdt.0002.txt", ... > > > Any suggestions > M > -- > > > Matt Curcio > M: 401-316-5358 > E: matt.curcio.ri at gmail.com > > ______________________________________________ > 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. >
Hmmm... Got this error Error in formatC(i, width = 4, format = "d", flat = "0") : unused argument(s) (flat = "0") Any ideas, M On Sun, Jul 31, 2011 at 1:30 PM, Matt Curcio <matt.curcio.ri at gmail.com> wrote:> Greetings all, > I would like to append a 4 digit number suffix to the names of my > files for later use. ?What I am using now only produces 1 or 2 or 3 or > 4 digits. > > ############ > for (i in 1:1000) { > ? temp <- (kegg [i,]) > ? temp <- merge (temp, subrichcdt, by="gene") > ? ? ?file.name <- paste ("kegg.subrichcdt.", i, ".txt", sep="") > ? ? ?write.table(temp, file=file.name) > } > ####### > But I want: > "kegg.subrichcdt.0001.txt" > "kegg.subrichcdt.0002.txt", ... > > > Any suggestions > M > -- > > > Matt Curcio > M: 401-316-5358 > E: matt.curcio.ri at gmail.com >-- Matt Curcio M: 401-316-5358 E: matt.curcio.ri at gmail.com
R. Michael Weylandt <michael.weylandt@gmail.com>
2011-Jul-31 18:30 UTC
[R] Appending 4 Digits On A File Name
Sorry, a typo on my end: argument is flag, not flat... On Jul 31, 2011, at 1:26 PM, Matt Curcio <matt.curcio.ri at gmail.com> wrote:> Hmmm... > Got this error > > Error in formatC(i, width = 4, format = "d", flat = "0") : > unused argument(s) (flat = "0") > > Any ideas, > M > > On Sun, Jul 31, 2011 at 1:30 PM, Matt Curcio <matt.curcio.ri at gmail.com> wrote: >> Greetings all, >> I would like to append a 4 digit number suffix to the names of my >> files for later use. What I am using now only produces 1 or 2 or 3 or >> 4 digits. >> >> ############ >> for (i in 1:1000) { >> temp <- (kegg [i,]) >> temp <- merge (temp, subrichcdt, by="gene") >> file.name <- paste ("kegg.subrichcdt.", i, ".txt", sep="") >> write.table(temp, file=file.name) >> } >> ####### >> But I want: >> "kegg.subrichcdt.0001.txt" >> "kegg.subrichcdt.0002.txt", ... >> >> >> Any suggestions >> M >> -- >> >> >> Matt Curcio >> M: 401-316-5358 >> E: matt.curcio.ri at gmail.com >> > > > > -- > > > Matt Curcio > M: 401-316-5358 > E: matt.curcio.ri at gmail.com > > ______________________________________________ > 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.
Michael, Got it, thanks. Looking over the man file realized it is FLAG not flat. Cheers, M On Sun, Jul 31, 2011 at 2:26 PM, Matt Curcio <matt.curcio.ri at gmail.com> wrote:> Hmmm... > Got this error > > Error in formatC(i, width = 4, format = "d", flat = "0") : > ?unused argument(s) (flat = "0") > > Any ideas, > M > > On Sun, Jul 31, 2011 at 1:30 PM, Matt Curcio <matt.curcio.ri at gmail.com> wrote: >> Greetings all, >> I would like to append a 4 digit number suffix to the names of my >> files for later use. ?What I am using now only produces 1 or 2 or 3 or >> 4 digits. >> >> ############ >> for (i in 1:1000) { >> ? temp <- (kegg [i,]) >> ? temp <- merge (temp, subrichcdt, by="gene") >> ? ? ?file.name <- paste ("kegg.subrichcdt.", i, ".txt", sep="") >> ? ? ?write.table(temp, file=file.name) >> } >> ####### >> But I want: >> "kegg.subrichcdt.0001.txt" >> "kegg.subrichcdt.0002.txt", ... >> >> >> Any suggestions >> M >> -- >> >> >> Matt Curcio >> M: 401-316-5358 >> E: matt.curcio.ri at gmail.com >> > > > > -- > > > Matt Curcio > M: 401-316-5358 > E: matt.curcio.ri at gmail.com >-- Matt Curcio M: 401-316-5358 E: matt.curcio.ri at gmail.com