Using double quotes fixes the problem for me
\documentclass{article}
\begin{document}
<<hash>>=
# Set 'a' to an octothorpe or hash sign:
a<-"#"
@
\end{document}
Seems like a bug with formatR though.
Domanda
How do I use knitr to tidy code including hash signs?
\documentclass{article}
\begin{document}
<<hash>>=
# Set 'a' to an octothorpe or hash sign:
a<-'#'
@
\end{document}
With purl I get an Warning and Error like this:
...
Warning in block_exec(params) :
failed to tidy R code in chunk <hash>
reason: Error in base::parse(text = text, srcfile = NULL) :
2:30: unexpected INCOMPLETE_STRING
2: a<-' %InLiNe_IdEnTiFiEr% "#' "
...
The generated LaTeX and pdf look OK, but the warning is disconcerting.
I'm using ESS within Aquamacs on a Mac.
Soluzione
Using double quotes fixes the problem for me
\documentclass{article}
\begin{document}
<<hash>>=
# Set 'a' to an octothorpe or hash sign:
a<-"#"
@
\end{document}
Seems like a bug with formatR though.