On 10/11/06, Marc Schwartz <[EMAIL PROTECTED]> wrote:
> On Wed, 2006-10-11 at 13:30 -0400, Charles Annis, P.E. wrote:
> > Greetings:
> >
> > I've searched the R archives with no luck.
> >
> > I want to print this to the screen as part of on-screen instructions as an
> > example:
> >
> > default.FACTOR.labels <- c("Probe1", "Probe2", "Probe3")
> >
> > I can't seem to trick gsub()
> >
> > gsub("'", "\"", "default.FACTOR.labels <- c('Probe1', 'Probe2', 'Probe3'))")
> >
> > [1] "default.FACTOR.labels <- c(\"Probe1\", \"Probe2\", \"Probe3\"))"
> >                                 ^       ^   ^       ^   ^       ^
> >
> > which gives me \" rather than "
> >
> > Is it possible to escape the " character?
> >
> > Thanks.
> >
> > Charles Annis, P.E.
>
>
> You don't need the gsub() and you want to use cat() to output the text:
>
>
> > cat("default.FACTOR.labels <- c(\"Probe1\", \"Probe2\", \"Probe3
>       \")\n")
> default.FACTOR.labels <- c("Probe1", "Probe2", "Probe3")
>
>
> cat() will properly interpret and output the escaped characters.  The
> newline character "\n" will return the cursor to the next line, so that
> the R prompt is not at the end of the last line output.
>

Also you could use single quotes to avoid having to escape the
double quotes in the string:

cat('default.FACTOR.labels <- c("Probe1", "Probe2", "Probe3")\n')

______________________________________________
R-help@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
and provide commented, minimal, self-contained, reproducible code.

Reply via email to