The sanitizeLatexString function sanitizes a LaTeX string by escaping special characters. It is strongly based on the function described on http://stackoverflow.com/questions/5406071/r-sweave-latex-escape-variables-to-be-printed-in-latex by Aaron Rendahl.
rnwString.initiate(studyName, authorName, docClassArgs = 'a4paper,portrait,11pt', newPage = TRUE, pageMargins=15)
rnwString.terminate(rnwString)
rnwString.generate(rnwString, rnwPath, fileName, pdfLatexPath, envir = parent.frame())
sanitizeLatexString(str)
hasLaTeX(pdfLatexPath)
In Windows, you can download (portable) MikTex from http://miktex.org/portable. You then decide yourself where to install MikTex; pdflatex will end up in a subfolder 'miktex\bin', so if you installed MikTex in, for example, 'C:\Program Files\MikTex', the total path becomes 'C:\Program Files\MikTex\miktex\bin'. Note that R uses slashes instead of backslashes to separate folders, so in this example, pdfLatexPath should be 'C:/Program Files/MikTex/miktex/bin'
In MacOS, you can install MacTex from http://tug.org/mactex/ By default, pdflatex ends up in folder '/user/texbin', which is what pdfLatexPath should be in that default case.
In Ubuntu, you can install TexLive base by using your package manager to install texlive-latex-base, or using the terminal: 'sudo apt-get install texlive-latex-base' In ubuntu, by default pdflatex ends un in folder '/usr/bin', which is what pdfLatexPath should be in that default case.
### sanitize a string
newString <- sanitizeLatexString('this is a tilde: ~.');
newString;
### newString is now: "this is a tilde: \~."
Run the code above in your browser using DataCamp Workspace