[R] Escaping quotes WAS: Storing long string with white space in variable

Charles C. Berry ccberry at ucsd.edu
Wed Oct 19 20:32:02 CEST 2016

On Wed, 19 Oct 2016, G.Maubach at weinwolf.de wrote:

> Hi All,
> I would like to store a long string with white space in a variable:
> -- cut --
>  # Create README.md
>  readme <- "---
> title: "Your project title here"
> author: "Author(s) name(s) here"
> date: "Current date here"
> output: html_document
> ---


> "
> cat(readme, file = "README.md")
> -- cut --
> I am looking for an equivalent to Pythons """  """ long string feature.

Whitespace isn;t the issue here. Embedded quotes are the problem.



In this case, if your replace the first and last double quotes with single 
quotes, you will get a single string of 464 characters, which is what you 

In other cases where you have embedded single quotes, you can escape them 
and the double quotes and get what you want.


> PS: This is a template for a project folder for each project. I would like
> to create it with R script instead of distributing it as a template file.
> This way one needs only the R script to setup a project like this:

[rest deleted]

There are templating procedures available. Package brew might be worth a 
look. It can take a template string with embedded R code and return 
a string with the R results spliced in. Package knitr has some ability to 
deal with templates, too, and I think there are other packages.

Jeff Newmiller's suggestion to make a package seems right to me whether 
you use brew or not. Long term it will probably be the easiest path.



More information about the R-help mailing list