Re: [R] save in for loop

From: Joris Meys <jorismeys_at_gmail.com>
Date: Fri, 04 Jun 2010 12:46:16 +0200

On a side note:

On Thu, May 20, 2010 at 9:43 AM, Ivan Calandra <ivan.calandra_at_uni-hamburg.de> wrote:
> Thanks to all of you for your answers!
>
> ...
>
> Tao, I don't understand why you have backslashes before "file" and after
> .rda. I guess it's something about regular expression, but I'm still
> very new to it.
> eval(parse(text=paste("save(file", i, ", file=\"file", i, ".rda\")",
> sep="")))
>
Very simple: You need to give a command as a string. In the save command, you have to put quotation marks around the filename. Now within the paste function, a simple quotation mark would make R believe the string to paste ends there, and you don't want that. So you escape the " by typing \", then R knows you want to add the symbol " to the string instead of end it. :

> paste("save(file", i, ", file=\"file", i, ".rda\")",sep="")
[1] "save(file2, file=\"file2.rda\")"

> parse(text=paste("save(file", i, ", file=\"file", i, ".rda\")",sep=""))

expression(save(file2, file="file2.rda")) attr(,"srcfile")
<text>

> paste("save(file", i, ", file="file", i, ".rda")",sep="")
Error: unexpected symbol in "paste("save(file", i, ", file="file"

Hope it's a bit more clear now.
Cheers
Joris

-- 
Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

tel : +32 9 264 59 87
Joris.Meys_at_Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

______________________________________________
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.
Received on Fri 04 Jun 2010 - 10:48:26 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 04 Jun 2010 - 11:20:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive