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")
精彩评论