开发者

how do I store as a string a long quote (with weird characters)

开发者 https://www.devze.com 2023-03-15 22:44 出处:网络
For example, I would like to store the string below (including the endlines), but I cannot figure out what the function is. I thought quote() would work:

For example, I would like to store the string below (including the endlines), but I cannot figure out what the function is. I thought quote() would work:

mystring <- quote(
\documentclass{article}

\usepackage{graphicx}

\begin{document}

%\tableofcontents
\addcontentsline{toc}{chapt开发者_JAVA技巧er}{List of Figures}
\listoffigures

\newpage
\stepcounter{figure}
)

but no luck.

Thank you, Xu.


You need to escape the backslashes:

mystring <- "
\\documentclass{article}

\\usepackage{graphicx}

\\begin{document}

%\\tableofcontents
\\addcontentsline{toc}{chapter}{List of Figures}
\\listoffigures

\\newpage
\\stepcounter{figure}
"
cat(mystring)
#
# \documentclass{article}
#
# \usepackage{graphicx}
#
# \begin{document}
#
# %\tableofcontents
# \addcontentsline{toc}{chapter}{List of Figures}
# \listoffigures
#
# \newpage
# \stepcounter{figure}
#

# assuming your string is stored in "foo.txt"
mystring <- paste(readLines("foo.txt"), collapse="\n")
0

精彩评论

暂无评论...
验证码 换一张
取 消