[R] paste argument of a function as a file name
Barry Rowlingson
B.Rowlingson at lancaster.ac.uk
Thu Nov 10 14:47:21 CET 2005
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
More information about the R-help
mailing list