Thank you for your help. It works now.

2011/10/13 Jean V Adams <jvad...@usgs.gov>

>
> Kristian Lind wrote on 10/13/2011 04:52:16 AM:
>
> >
> > Dear R-users,
> >
> > I'm writing a program that constructs a dataset. I wish to save the
> dataset
> > to a file.
> >
> > Here's a very simple example of what I'm trying to do
> >
> > function(x=peter){
> > y <- x/2
> > write.csv(y, file = "...\x")
> > }
> >
> > The problem is that I want to name the dataset as whatever the name of
> the
> > input is. In this case peter.
> > How do I do this?
> >
> > Thank you in advance.
> >
> > Kristian
>
>
> I think you're looking for something like this
>
> foo <- function(x){
>         y <- x/2
>         file.name <- paste("...\\", deparse(substitute(x)), ".csv",
> sep="")
>         # I include the print() functions just so you can see what happened
>         print(y)
>         print(file.name)
>         write.csv(y, file=file.name)
>         }
>
> peter <- 12
> foo(peter)
>
>
> Jean

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to