[R] paste argument of a function as a file name

Romain Francois francoisromain at free.fr
Thu Nov 10 14:49:28 CET 2005


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                                  |
+---------------------------------------------------------------+




More information about the R-help mailing list