R-help,
I have a function which is exporting the output to a file via
write.table(df, file = "file name.xls" )
What I want is to paste the file name (above) by taking the argument to
the function as a file name
something like this:
MY.function<- function(df)
{
...
...
write.table(df,"argument.xls")
}
MY.function(argument)
Thank you
On 11/10/05 8:28 AM, "Luis Ridao Cruz" <Luisr at frs.fo> wrote:> R-help, > > I have a function which is exporting the output to a file via > write.table(df, file = "file name.xls" ) > > What I want is to paste the file name (above) by taking the argument to > the function as a file namehelp('paste') Sean
Luis Ridao Cruz wrote:> R-help, > > I have a function which is exporting the output to a file via > write.table(df, file = "file name.xls" ) > > What I want is to paste the file name (above) by taking the argument to > the function as a file name > > something like this:More like this: foo = function(df){ fn=paste(deparse(substitute(df)),'.xls',sep='') write.table(df,file=fn) } Then: x=1:10 foo(x) produces a file: x.xls deparse(substitute(df)) is used in plot() to label the Y-axis with the name of the object passed to plot(), which is similar to what you want to do here. Baz
Le 10.11.2005 14:28, Luis Ridao Cruz a ??crit :>R-help, > >I have a function which is exporting the output to a file via >write.table(df, file = "file name.xls" ) > >What I want is to paste the file name (above) by taking the argument to >the function as a file name > >something like this: > >MY.function<- function(df) >{ >... >... >write.table(df,"argument.xls") >} >MY.function(argument) > > >Thank you > >Hi, Maybe sprintf or paste. MY.function<- function(df, arg="argument") { ... ... write.table(df,paste(arg,".xls",sep="")) # or : # write.table(df,sprintf("%s.xls",arg)) } MY.function(argument) -- visit the R Graph Gallery : http://addictedtor.free.fr/graphiques +---------------------------------------------------------------+ | Romain FRANCOIS - http://francoisromain.free.fr | | Doctorant INRIA Futurs / EDF | +---------------------------------------------------------------+
Adaikalavan Ramasamy
2005-Nov-10 13:50 UTC
[R] paste argument of a function as a file name
my.write <- function( obj, name ){
filename <- file=paste( name, ".txt", sep="")
write.table( obj, file=filename, sep="\t", quote=F)
}
my.write( df, "output" )
Regards, Adai
On Thu, 2005-11-10 at 13:28 +0000, Luis Ridao Cruz
wrote:> R-help,
>
> I have a function which is exporting the output to a file via
> write.table(df, file = "file name.xls" )
>
> What I want is to paste the file name (above) by taking the argument to
> the function as a file name
>
> something like this:
>
> MY.function<- function(df)
> {
> ...
> ...
> write.table(df,"argument.xls")
> }
> MY.function(argument)
>
>
> Thank you
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>
Frede Aakmann Tøgersen
2005-Nov-10 13:57 UTC
[R] paste argument of a function as a file name
Why not use something like
MY.function <- function(x){
filn <- deparse(substitute(x))
filename <- paste(filn,"xls",sep=".")
...
...
write.table(x,file=filename)
}
Med venlig hilsen
Frede Aakmann T??gersen
> -----Oprindelig meddelelse-----
> Fra: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] P?? vegne af Luis Ridao Cruz
> Sendt: 10. november 2005 14:28
> Til: r-help at stat.math.ethz.ch
> Emne: [R] paste argument of a function as a file name
>
> R-help,
>
> I have a function which is exporting the output to a file via
> write.table(df, file = "file name.xls" )
>
> What I want is to paste the file name (above) by taking the
> argument to the function as a file name
>
> something like this:
>
> MY.function<- function(df)
> {
> ...
> ...
> write.table(df,"argument.xls")
> }
> MY.function(argument)
>
>
> Thank you
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
Luis Ridao Cruz wrote:> R-help, > > I have a function which is exporting the output to a file via > write.table(df, file = "file name.xls" ) > > What I want is to paste the file name (above) by taking the argument to > the function as a file name > > something like this: > > MY.function<- function(df) > { > ... > ... > write.table(df,"argument.xls") > } > MY.function(argument)Has been asked hundreds of times on this list. Please check the archives as the posting guide asks to do ... Hint: paste() Uwe Ligges> > Thank you > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html